iPhone SDK - 以编程方式添加UINavigationController [英] iPhone SDK - Add a UINavigationController Programmatically
问题描述
我有一个iPhone项目,其中目前没有 UINavigationController
。相反,我通过自己处理视图层次结构来交换视图。但是 - 你可能知道 - 这是不好的做法,所以我想弄清楚如何在我当前的应用程序中实现 UINavigationController
。我显然可以开始我的项目并使用Xcode模板,但我真的不想这样做。
I have an iPhone project which currently does not have a UINavigationController
in it. Instead I swap views by handling the view hierarchy myself. However - as you're probably aware - this is bad practice, so I am trying to figure out how to implement a UINavigationController
into my current app. I can obviously start my project over and use an Xcode template, but I really don't want to do this.
必须有办法做到这一点以编程方式。但我无法弄清楚需要在AppDelegate中使用哪些代码。有人对这个有经验么?我现在处于亏损状态。
There must be a way to do this programmatically. But I can't figure out what code needs to go in the AppDelegate. Does anyone have any experience with this? I am at a loss at the moment.
干杯,
Brett
Cheers, Brett
推荐答案
Yeap。
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
navController=[[UINavigationController alloc] init];
MyViewController *firstController=[[MyViewController alloc] init];
[navController pushViewController:firstController animated:NO];
[window addSubview: navController.view];
}
- (void) dealloc
{
...
[navController release];
...
}
这是一个很常见的问题,看看在这个....
以编程方式在UIViewController中添加UINavigationController
It's a quite common question, have a look at this too.... Programmatically add UINavigationController in UIViewController
这篇关于iPhone SDK - 以编程方式添加UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!