我正在尝试使用 UINavigationController 进行一种“从左到右”的分层导航。我正在使用这段代码:
-(IBAction)showSettings:(id)sender {
UINavigationController *aNavController = [[UINavigationController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:aNavController animated:YES];
SecondView *secondView = [[SecondView alloc] initWithNibName:nil bundle:nil];
[aNavController pushViewController:secondView animated:NO];
UIBarButtonItem *aButton = [[UIBarButtonItem alloc] initWithTitle:@"Knapp" style:UIBarButtonItemStylePlain target:self action:@selector(nextView:)];
aNavController.topViewController.navigationItem.rightBarButtonItem = aButton;
[aButton release];
[secondView release];
[aNavController release]; }
-(IBAction)nextView:(id)sender {
ThirdView *thirdView = [[ThirdView alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:thirdView animated:YES];
NSLog(@"Push it like it's hot"); }
'nextView' 被正确调用,“Push it like it's hot”打印在“Output”中,但没有推送任何内容,没有新视图出现。我也尝试过更改:
[self.navigationController pushViewController:thirdView animated:YES];
to[self.navigationController popViewControllerAnimated:YES];
但结果保持不变,没有任何反应。
我的结论是:我在'nextView'的self.navigationController部分做错了,即程序不知道从/到什么推/弹出。我已尽力查看有关此的某种文档,但我无法解决,所以我在这里。
self.navigationController 是正确的方法还是我在该行中遗漏了什么?
提前谢谢你,托拜厄斯·托维达尔