xcode 如何将 UINavigationController 添加到显示为 Modal 的 UIViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15058644/
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
How to add an UINavigationController to an UIViewController presented as Modal
提问by Sebastian
I have an alternative flow in my app. This flow starts in my firstViewController, then in this view a call my secondViewController like this:
我的应用程序中有一个替代流程。这个流程从我的 firstViewController 开始,然后在这个视图中像这样调用我的 secondViewController:
- (IBAction)PressButton:(id)sender {
SecondViewController *second = [[SecondViewController alloc] init];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *nav = self.navigationController;
[nav presentViewController:second animated:YES completion:nil];
}
In my secondViewController I want to push my thirdViewController. But it is not working I tried this ways:
在我的 secondViewController 中,我想推送我的thirdViewController。但它不起作用我试过这种方式:
- (IBAction)pressButton:(id)sender {
ThirdViewController *tvc = [[ThirdViewController alloc] init];
UINavigationController *nav = self.navigationController;
[nav pushViewController:tvc animated:YES];
}
}
When I press the button of secondViewController nothing happens.
当我按下 secondViewController 的按钮时,什么也没有发生。
What I'm doing wrong ?
我做错了什么?
I'm using:
我正在使用:
- OSX 10.8.2
- Xcode 4.6
- iOS 6.1
- OSX 10.8.2
- Xcode 4.6
- iOS 6.1
回答by Chad Edrupt
You must present the navigation controller modally, and have the second view as the root of that navigation controller. As well as calling presentViewController from the owning view not its parent navigation controller.
您必须以模态方式呈现导航控制器,并将第二个视图作为该导航控制器的根。以及从拥有视图而不是其父导航控制器调用presentViewController。
- (IBAction)PressButton:(id)sender {
SecondViewController *second = [[SecondViewController alloc] init];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:second];
[self presentViewController:navigationController animated:YES completion:nil];
}
回答by Aaron Wojnowski
Instead of presenting just the second view controller, make sure to present an additional navigation controller.
不要只展示第二个视图控制器,确保展示一个额外的导航控制器。
SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[[self navigationController] presentViewController:navigationController animated:YES completion:nil];
回答by Harikrishnan
If you are using storyboard just click on the source view xib, Ctrl+drag to destination (Create Segue), select modal from popup menu.Click on the newly created connection. Add a name for it then in source view controller [self performSegueWithIdentifier:@"Segue Name" sender:self];
如果您正在使用故事板,只需单击源视图 xib,按住 Ctrl 键并拖动到目标(创建 Segue),从弹出菜单中选择模式。单击新创建的连接。为它添加一个名称,然后在源视图控制器中 [self performSegueWithIdentifier:@"Segue Name" sender:self];
回答by trludt
If you are trying to get a button to direct you to a different page modally, you can go into the storyboard or xib file. Control click from that button to the view controller you want to go to. and then the popup menu will give you the options of what type of outlet you want to use. Hope this helps
如果您想获得一个按钮以模态方式将您定向到不同的页面,您可以进入故事板或 xib 文件。控制从该按钮单击到您要转到的视图控制器。然后弹出菜单将为您提供要使用的插座类型的选项。希望这可以帮助