在设置了简单的导航控制器(启动基于导航的应用程序项目)后,我创建了一个带有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";
,所以我在导航栏中得到了标题和返回按钮(因为我在HomeViewController
上也有相同的设置)。
我认为NavigationViewController会处理当前视图的弹出,但它没有。
我该怎么做才能弹出
SimpleSearchViewController
?我在哪里使用
[self.navigationController popViewControllerAnimated:YES];
因为视图还在那里,而ViewDidUnload
从未被调用。
我的想法是这应该在第一个视图控制器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的根控制器
self.title = @"Home";
即可。 - balexandreviewWillDisappear
是一个很好的帮手。 :-) - Sebastian Roth