Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to refer to methods in masterviewcontroller from detailviewcontroller

Posted on 2013-06-23
Medium Priority
Last Modified: 2013-06-30
I'm trying to develop a flashcard type app. My questions and answers are image files. I've created a master-detail application.

My questions are loaded into an array in the MasterViewController. The app opens at the MasterViewController table listing of questions and I can choose a question which then opens up to the DetailViewController.

The DetailViewController is just a single imageView. I have put gesture recognizers for tap, swipe left and swipe right. Tap can correctly move to the answer image and back. I want the swipe left and swipe right to go back to the MasterViewController and run methods userSwipedRightOnChild and  FindNextQuestion  which I have set up but I can't work out how to go back there.

- (IBAction)foundSwipeRight:(id)sender {
    [ self.presentedViewController) userSwipedRightOnChild]; //doesn't work
   // NSLog(@"Presenting View controller: %@", [self.presentedViewController class]); //gives null
    self.detailImageView.image=[UIImage imageNamed:[self.detailItem objectForKey:@"questionpicture"]];
    questionnowshowing = TRUE;
Question by:onewheelhk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 20

Expert Comment

ID: 39271919
There is no trick here, the master and detail viewControllers are just classes and if you want the two classes to communicate then you will need one of them to have an reference to the other.  You could pass the master to the detail the first time you go to the detail, or you could use a Delegate protocol in the detail viewController and have your master subscribe to it.

If this is an iPhone app and you are segueing from the two views then you could just go back from the detail to the master.

Author Comment

ID: 39287709
I've requested that this question be deleted for the following reason:

I think I don't understand enough about view controllers. I'm now trying to do this using a different method. Thanks.
LVL 20

Accepted Solution

darbid73 earned 2000 total points
ID: 39287707
which part of my answer did you not understand?  I see you are an Office Expert of more than 10 years so I am sure the concepts are not that hard.  

Your controllers are just classes and you need one class to hold a reference to the other or you need to have one implement a Delegate protocol.  Further depending on which one you want to use I can link you to many blogs and examples of these two methods as they are needed all the time in an iOS app thus even if you do not do it here you will need to do this elsewhere very soon.
LVL 20

Expert Comment

ID: 39287710
ID: 39287707 was meant to be an objection.

Author Closing Comment

ID: 39287832
Thanks for your help and I'm happy to give you the points - but I'm now trying to implement this using a page controller instead. I just couldn't get the swipe on the image to go back to the parent without a button on the navigation bar and I couldn't see what the problem was.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What's a UDID? If you're involved in developing, testing, or even reviewing an iOS application that's in beta, then at some point you may need to know the UDID for any iOS devices that you'll be testing on. What's the UDID? It stands for Unique Dev…
The release of the iPhone 6 and the iPhone 6 Plus was extremely successful for Apple. However when iOS 8.1 was introduced, many iPhone users complained of quick battery drainage. Without even knowing, you may be unnecessarily using up your battery p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

662 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question