Solved

How to refer to methods in masterviewcontroller from detailviewcontroller

Posted on 2013-06-23
5
465 Views
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;
             
}
0
Comment
Question by:onewheelhk
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:darbid73
Comment Utility
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
 
LVL 1

Author Comment

by:onewheelhk
Comment Utility
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
 
LVL 19

Accepted Solution

by:
darbid73 earned 500 total points
Comment Utility
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
 
LVL 19

Expert Comment

by:darbid73
Comment Utility
ID: 39287707 was meant to be an objection.
0
 
LVL 1

Author Closing Comment

by:onewheelhk
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final 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 http://bit.ly/XDcourse.

744 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

13 Experts available now in Live!

Get 1:1 Help Now