如何将现有的UIViewController(使用presentModalViewController呈现)添加到UINavigationController?
当用户点击按钮时,需要推送我的详细视图的新副本。 (换句话说,pushViewController在UINavigationController中以模态方式显示pushViewController)。
启用此功能的最简单方法是什么?
答案 0 :(得分:37)
如何创建模态viewcontroller?只需将控制器包装到UINavigationController
中我们假设你的模态代码是这样的:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
[self presentModalViewController:vc animated:YES];
然后将其更改为以下内容:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
答案 1 :(得分:0)
我认为您需要在委托中添加导航控制器,之后您可以推送视图。这样您就可以从应用程序的任何位置推送视图。
在AppDelegate.h上
UINavigationController *navig;
在AppDelegate.M上
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
navig = [[UINavigationController alloc] initwithRootViewController:viewController.view];
//[navig pushViewController:viewController animated:YES];
[self.window addSubview:navig.view];
[self.window makeKeyAndVisible];
return YES;
}