views:

1021

answers:

1

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.

+1  A: 

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.

Ican Zilb
Thanks Ican. Your response looks like the correct answer, but I must have my code all jacked-up such that I can't get it to work as simply as you have stated. I will refactor my code (i.e., start over :)) and when I get it working, I will tag yours as the answer.
mobibob
I have almost got it... I have the navigation to/from, but it is not modal. Tonight, I should finish this and post my new learning.
mobibob
OK. I read the doc's (again) as Ican suggested and the line that tipped me off was the statement about "loadView" method. As soon as I put that in my head along with the knowledge that I had done an "addSubview" of my About page's view, I realized that I needed a 'removeSubview' of sorts. What I found is in the attached code-(IBAction) dismissAbout: (id) sender { NSLog(@"%s", __FUNCTION__ ); [self.view removeFromSuperview]; [self dismissModalViewControllerAnimated:YES];}Ican, you get the answer check-mark. Thanks!
mobibob