Reputation: 45
Basically the problem I am having is I am unable to call a method in my Main view controller(called Recorder) from another view called Table.
The table view is loaded as a Modalview controller(presentmodalViewController) from Recorder when the user clicks on a button. The table view lets my users change from setting 1 to setting 2 and has a done button (which calls dismissmodalviewcontroller) and returns the user to the main view(Recorder).
What I want is to call a method in Recorder when the done button is clicked on Table View. This method is called Changeview and changes the setting. I am currently unable to call this method properly.
The current code I have is:
changeView method
- (void)changeView
{
[levelsView changeView];
}
TableViewController interface file
RecorderViewController*recorderViewController;
@property (nonatomic, retain) RecorderViewController *recorderViewController;
TableViewController implementation file
@synthesize recorderViewController;
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[recorderViewController changeView];
}
Method called when Done button is pressed
- (IBAction) Switch: (id) sender {
[self dismissModalViewControllerAnimated:YES];
}
The current code does not give me any errors but it also does not change the setting. I have also tried to setup notifications with no luck. Any insight into this?
Upvotes: 1
Views: 2112
Reputation: 7417
Are you setting the value of recorderViewController when you initialize the tableViewController (i.e., are you setting tableViewController.recorderViewController = self
in your Recorder class)? If not, then your call to [recorderViewController changeView]
is sending a message to nil – which doesn't crash, but it doesn't do anything either.
As an aside, passing your TableViewController a reference to your RecorderViewController is probably not the best way for two controllers to communicate: You may want to consider using NSNotificationCenter, or passing a model object and using Key-Value Observing.
Upvotes: 1