How to refer to methods in masterviewcontroller from detailviewcontroller

Posted on 2013-06-23
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
  • 3
  • 2
LVL 19

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 19

Accepted Solution

darbid73 earned 500 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 19

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The Basics of Storyboard Storyboards were first introduced to developers in the release of iOS 5. They save the developer the trouble of designing each screen’s interface in a different file. The storyboard allows you to see the conceptual mockup o…
     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON ( If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
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
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now