Jhorra
Jhorra

Reputation: 6321

Error calling method on parent viewcontroller from modal window

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?

Upvotes: 1

Views: 555

Answers (1)

bandejapaisa
bandejapaisa

Reputation: 26952

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.

Upvotes: 2

Related Questions