如何以编程方式添加导航控制器?

时间:2010-03-10 08:54:28

标签: iphone iphone-sdk-3.0

在我的应用程序中,要求我在笔尖中有6个按钮, 当我按下任何按钮时,根据按下的按钮,新的笔尖将被加载到窗口中。问题是加载新笔尖后如果我想回到前一个笔尖(它有所有按钮)如何添加导航控制器?

我现在正在做的是在按下按钮时加载新笔尖

objNewViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[self.navigationController pushViewController:objNewViewController animated:YES];

但是通过这种方式我无法加载笔尖,它没有执行任何操作?

2 个答案:

答案 0 :(得分:6)

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil]];

[self presentModalViewController:navigationController               animated:YES];
            [navigationController release];

在NewViewController中: 用这个来解雇并回到之前的观点。

[[self navigationController] dismissModalViewControllerAnimated:YES];

答案 1 :(得分:0)

Xcode中有一个基于导航的应用程序的模板。它完成了你描述的一切。好吧,至少非常接近,只有AnotherViewController中的-tableView:didSelectRowAtIndexPath:被注释掉了。

相关问题