Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

How to refer to methods in masterviewcontroller from detailviewcontroller

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;
             
}
0
onewheelhk
Asked:
onewheelhk
  • 3
  • 2
1 Solution
 
darbid73Commented:
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.
0
 
onewheelhkAuthor Commented:
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.
0
 
darbid73Commented:
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.
0
 
darbid73Commented:
ID: 39287707 was meant to be an objection.
0
 
onewheelhkAuthor Commented:
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.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now