xcode 将 UINavigationController 添加到现有的 UIViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4957878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding UINavigationController to existing UIViewController
提问by marko
How do I add an existing UIViewController (which is presented using presentModalViewController) to a UINavigationController?
如何将现有的 UIViewController(使用 presentModalViewController 呈现)添加到 UINavigationController?
When user tap on button, a new copy of my detail view need to be pushed. (In other words, pushViewController displaying pushViewController, modally, in a UINavigationController).
当用户点击按钮时,需要推送我的详细信息视图的新副本。(换句话说,pushViewController 在 UINavigationController 中模态地显示 pushViewController)。
Easiest way to enable this functionality?
启用此功能的最简单方法是什么?
回答by Matthias Bauch
how do you create your modal viewcontroller? Just wrap the controller into a UINavigationController
你如何创建你的模态视图控制器?只需将控制器包装成 UINavigationController
Let's assume your modal code is like this:
让我们假设你的模态代码是这样的:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
[self presentModalViewController:vc animated:YES];
Then change it into something like this:
然后把它改成这样:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
回答by Splendid
I think you need to add a navigation controller in your delegate, after that you can push the view. So that you can push the view from anywhere in your application.
我认为您需要在您的委托中添加一个导航控制器,然后您可以推送视图。这样您就可以从应用程序的任何位置推送视图。
on AppDelegate.h
在 AppDelegate.h 上
UINavigationController *navig;
on AppDelegate.M
在 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;
}