Reputation: 8794
I have read all the other user's accounts of problems, but they don't seem to conclude with a result that works for me or they end with 'I fixed it guys - thanks for the help', but then they neglected to share their solution. Here is my code to present and dismiss (all key objects are properties of my application delegate. I am trying to bring up an About page and then return to the application. What did I do wrong??
Present modal VC (works):
-(IBAction) showInfoButton: (id) sender {
NSLog(@"%s", __FUNCTION__);
if( aboutViewController == nil ) {
aboutViewController = [[[AboutViewController alloc] initWithNibName:@"About" bundle:[NSBundle mainBundle]] autorelease];
[appDelegate.window addSubview: aboutViewController.view];
}
appDelegate.modalNavigationController = [[UINavigationController alloc] initWithRootViewController:aboutViewController];
[appDelegate.modalNavigationController presentModalViewController:appDelegate.modalNavigationController animated: YES];
}
My dismiss from the About View Controller (does not work):
-(IBAction) dismissAbout: (id) sender {
NSLog(@"%s", __FUNCTION__ );
[self dismissModalViewControllerAnimated:YES];
}
I have tried animation 'NO', but that did not make any difference. I have tried to match my code with others' code, but that did not make any difference. I am going around in circles, so any help is appreciated.
Upvotes: 2
Views: 10401
Reputation: 6397
The default template for a flipside controller in XCode, suggests you need to have a delegate in your modal controller, pointing you back to your initial controller. The easiest is if you create a new project in xcode, choose Utility application and have a look at the code.
In short, this should be the code in your main screen controller
- (IBAction)showInfo;
{
InfoScreen * aboutViewController = [[InfoScreen alloc] initWithNibName:@"InfoScreen" bundle:nil];
aboutViewController.delegate =self;
[self presentModalViewController: aboutViewController animated:YES];
[aboutViewController release];
}
- (void)flipsideViewControllerDidFinish;
{
[self dismissModalViewControllerAnimated:YES];
}
And this the Action of your back button in your about screen:
- (IBAction)done {
[self.delegate flipsideViewControllerDidFinish];
self.delegate = nil;
}
There's a bit more to the code in order to make delegate to respond to the flipsideViewControllerDidFinish, etc. which doesn't have to do with the dismissing of the controller which you are asking about, but looking in the Utility app template will make it clear.
Upvotes: 4