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
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 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
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
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

624 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