将UINavigationController添加到现有的UIViewController

mar*_*rko 9 iphone xcode uiviewcontroller uinavigationcontroller

如何将现有的UIViewController(使用presentModalViewController呈现)添加到UINavigationController?

当用户点击按钮时,需要推送我的详细视图的新副本.(换句话说,pushViewController在UINavigationController中以模态方式显示pushViewController).

最简单的方法来启用此功能?

Mat*_*uch 37

你如何创建模态viewcontroller?只需将控制器包装到UINavigationController中

我们假设你的模态代码是这样的:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
[self presentModalViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)

然后将其更改为以下内容:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
Run Code Online (Sandbox Code Playgroud)