开发者

NavigationController is not popping the Pushed View on Back button

Having a simple Navigation Controller in place (starting the Navigation Based Application project) I created a new View with a XIB file.

on my HomeViewController (Home screen with all options as UIButton's I have:

@implementation HomeViewController

-(IBAction) optionChoosed:(UIButton *)button
{
    NSString *msg = [NSString stringWithFormat:@"Button: %d", button.tag];
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Hi" message:msg delegate:nil cancelButtonTitle:@"Go away" otherButtonTitles:nil];
    
    switch (button.tag) {
        case 13:
            // Simple Search
            [self loadSimpleSearch]; break;
            
        default:
            [alert show];           
            break;
    }
    [alert release];
}

-(void)loadSimpleSearch
{
    SimpleSearchViewController *controller = 
        [[SimpleSearchViewController alloc] initWithNibName:@"SimpleSearchViewController" bundle:nil];
    
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

witch works great!

it Pushes the View int开发者_如何学Goo the front of the stack!

Now, because in my 2nd view SimpleSearchViewController I have self.title = @"myTitle"; I get the Title in the NavigationBar as well the back button (as I have the same setting on the HomeViewController)

I thought that the NavigationViewController would handle the pop of the current view, but it does not.

What do I have to do, to pop the SimpleSearchViewController?

Where do I use [self.navigationController popViewControllerAnimated:YES];

as the view continues there, and ViewDidUnload is never called.

My idea was that this should be handle in the first ViewController, the HomeViewController but I have no idea what is the method I should hook to, and I read the documentation and I can't figure it out :-/

Any help is greatly appreciated, thank you.

HomeViewController

alt text http://cl.ly/XNS/Screen_shot_2010-04-21_at_22.38.51.png

SimpleSearchViewController

alt text http://cl.ly/YDw/Screen_shot_2010-04-21_at_22.40.00.png

SimpleSearchViewController after pressing the Back button

alt text http://cl.ly/XLO/Screen_shot_2010-04-21_at_22.40.21.png


To add the image from a comment that asks if HomeViewController as the root controller for the NavigationViewController

NavigationController is not popping the Pushed View on Back button


Not sure if this helps but when implementing navigationItem in code, if you don't call the super the popping functionality will not be present

-(UINavigationItem*) navigationItem
{
    UINavigationItem* item = [super navigationItem];
    item.title = @"search";
    return item;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜