NavigationController没有弹出“后退推送视图”按钮

时间:2010-04-21 20:41:46

标签: cocoa-touch uiviewcontroller uinavigationcontroller

有一个简单的导航控制器(启动基于导航的应用程序项目)我创建了一个带有XIB文件的新视图。

在我的HomeViewController(主屏幕上,所有选项为UIButton我有:

@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];
}

巫婆很棒!

它将视图推入堆栈的前端!

现在,因为在我的第二个视图中SimpleSearchViewController我有self.title = @"myTitle";我在NavigationBar中获得了标题以及后退按钮(因为我在HomeViewController上有相同的设置)< / p>

我认为NavigationViewController会处理当前视图的弹出,但它没有。

  

我该怎么做,弹出SimpleSearchViewController

     

我在哪里使用 [self.navigationController popViewControllerAnimated:YES];

随着视图的继续,永远不会调用ViewDidUnload

我的想法是应该在第一个ViewController中处理HomeViewController,但我不知道我应该挂钩的方法是什么,我读了文档,我无法弄明白: - /

非常感谢任何帮助,谢谢

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

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


从评论中添加图像,询问HomeViewController是否为NavigationViewController的根控制器

alt text

1 个答案:

答案 0 :(得分:1)

不确定这是否有帮助,但在代码中实现navigationItem时,如果不调用super,则弹出功能将不存在

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