Error calling method on parent viewcontroller from modal window?

Anytime I see self. ParentViewController .... it's a code smell.

Up vote 1 down vote favorite share g+ share fb share tw.

What I have going on here is a page that shows a list of search results. When you click on the search button it opens a modal window where you can change your search criteria. When you click done it calls the updateSearch method on the modal window, which in turn should call the updateSearch on the parent window.

The error I get is Receiver type 'ehrxCMView' for instance message does not declare a method with selector 'updateSearch' Here is the method on the parent viewcontroller - (void)updateSearch { } Here is my method on the modal window - (IBAction)updateSearch:(id)sender { ehrxCMView *parent = (ehrxCMView*)self. ParentViewController; parent. SelectedOptions = self.

SelectedOptions; parent updateSearch; self dismissModalViewControllerAnimated:YES; } My one thought here is the modal window is inside a navigation controller, so I'm thinking maybe I need to go through that, then to the parent controller? Ios ios5 uinavigationcontroller modalviewcontroller parentviewcontroller link|improve this question asked Mar 21 at 17:05Jhorra397312 79% accept rate.

Anytime I see self. ParentViewController .... it's a code smell. Instead of linking view controllers like this, set one view controller as a delegate method on the popup controller.

The popup can then call it's delegate to tell it to updateSearch. This is a better, more maintainable approach you should get into the habit of doing.

Good suggestion. On a more abstract level, self. ParentViewController clearly isn't the value Jhorra thinks it is.

When debugging problems like this, it's always a good idea to find out what the computer thinks is happening, and then determine how that differs from what you think is happening. – Olie Mar 21 at 17:24 Thanks for the suggestions, I'm still new to this. Can you point me to more info on how to set the controllers as delegates?

I understand the concept, but I'm not familiar enough with IOS yet to do that. – Jhorra Mar 21 at 17:37 Have a look at the Cocoa fundamentals guide, which has a section on delegates. Developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/… – bandejapaisa Mar 21 at 17:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions