ios 'push segues 只能在源控制器由 UINavigationController 的实例管理时使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19223761/
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
'Push segues can only be used when the source controller is managed by an instance of UINavigationController
提问by Boggarapu
I am having a problem with this. In my root view controller I am having a textfield & one button. I am giving a condition like if i entered 0 in textfield then only it should move to next view. upto here it is working correctly. But now here is problem. Here I am having one button & given navigation to third view controller for that button. here i am getting error as
我遇到了这个问题。在我的根视图控制器中,我有一个文本字段和一个按钮。我给出的条件是,如果我在文本字段中输入 0,则只有它应该移动到下一个视图。到这里它工作正常。但现在问题来了。在这里,我有一个按钮并为该按钮导航到第三个视图控制器。在这里我收到错误
Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
image ref: http://img12.imageshack.us/img12/8533/myp5.png
图片参考:http: //img12.imageshack.us/img12/8533/myp5.png
and i am giving action for button in first view as below
我在第一个视图中对按钮进行操作,如下所示
- (IBAction)Submit:(id)sender {
if([tf.text isEqual:@"0"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SecondViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewControllerID" ];
[self presentViewController:vc2 animated:YES completion:NULL];
}
}
采纳答案by Jonathan Arbogast
After looking at your screenshot, you either need to
查看您的屏幕截图后,您要么需要
- Push your
SecondViewController
onto the existing navigation controller's stack instead of presenting it modally OR - You need to embed your
SecondViewController
in another navigation controller and then create and present thatnavigation controller modally from your SamplesViewController
- 将您的内容推
SecondViewController
送到现有导航控制器的堆栈上,而不是以模态方式呈现或 - 您需要将您
SecondViewController
的导航控制器嵌入到另一个导航控制器中,然后从您的 SamplesViewController 模态地创建和呈现该导航控制器
Either way, SecondViewController
needs to be embedded in a navigation controller before you can use Push Segues from it
无论哪种方式,都SecondViewController
需要嵌入到导航控制器中,然后才能从中使用 Push Segues
回答by Mutawe
Go To:
去:
Editor--> Embed In --> Navigation Controller, to add Navigation Controller
to your initial view
编辑器--> 嵌入--> 导航控制器,添加Navigation Controller
到您的初始视图
回答by Muhammad Irfan
Either embed your view controller in a Navigation controller or if there is a Navigation controller in the story board mak it the initial view controller
将您的视图控制器嵌入到导航控制器中,或者如果故事板中有导航控制器,则将其设为初始视图控制器
回答by chancyWu
Embed your view controller in a UINavigationController
is a good option if there is no UINavigationController
in the storyboard. Otherwise you can select the UINavigationController
and select the root view controller in the inspector pane, then drag it to the UIViewController
you want to use as root. the screenshot is as below:
UINavigationController
如果UINavigationController
情节提要中没有,则将您的视图控制器嵌入到 a 中是一个不错的选择。否则,您可以选择UINavigationController
并在检查器窗格中选择根视图控制器,然后将其拖到UIViewController
要用作根的 。屏幕截图如下:
回答by plaasm
I solved this by creating a custom UIStoryboardSegue between the UINavigationController and the destination view controller:
我通过在 UINavigationController 和目标视图控制器之间创建自定义 UIStoryboardSegue 解决了这个问题:
-(void) perform
{
assert([self.sourceViewController isKindOfClass:[MyNavigationController class]]);
MyNavigationController *launchController = (MyNavigationController *) self.sourceViewController;
[launchController setViewControllers:@[self.destinationViewController] animated:YES];
}
回答by Jaywant Khedkar
Try this. It works for me.when you set root view controller to first view and use self.presentViewController,controller move to next view but instance of navigation controller is only for first view,third view required navigation instance so use self.navigationControllerinstead of presentViewController.
尝试这个。它对我有用。当您将根视图控制器设置为第一个视图并使用self.presentViewController 时,控制器移动到下一个视图,但导航控制器的实例仅适用于第一个视图,第三个视图需要导航实例,因此使用self.navigationController而不是presentViewController。
NSString * storyboardName=@"Main";
UIStoryboard *storybord=[UIStoryboard storyboardWithName:storyboardName bundle:nil];
SecondViewController *vc=[storybord instantiateViewControllerWithIdentifier:@"SecondViewControllerID"];
[self.navigationController pushViewController:vc animated:YES];
回答by RootCode
I also faced same problem. My problem was I was using model
segue style (rather that push
) for one before the current controller because of that I think it broke the Navigation chain before already.
我也面临同样的问题。我的问题是我在当前控制器之前使用了model
segue 样式(而不是push
),因为我认为它之前已经破坏了导航链。