我正在使用 Storyboard开发第一个教程,我的要求是我有两个文本字段和一个按钮。当我单击按钮时,如果文本字段不为空,我想将 V1Controller 导航到 V2Controller。为此,我从 V1Controller 拖到 V2Controller 并赋予样式“Model”,我的标识符是 Storyboard 中的“DestinationView”。 在这里,我在点击按钮时在 V1Controller 中编写代码
if(!userField.text.length==0 && !passwordField.text.length==0)
{
[self performSegueWithIdentifier: @"DestinationView" sender: self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"DestinationView"])
{
SecondViewController *sVC =segue.destinationViewController;
[self presentViewController:sVC animated:YES completion:nil];
}
}
当我点击按钮时,应用程序崩溃并提供以下豁免:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图以模态方式呈现事件 Controller ”。
提前致谢
最佳答案
在您的案例中,您不应在 prepareForSegue
中调用 presentViewController
。这就是框架为您所做的。
例如,如果您想用一些数据加载 destinationViewController
,则应使用 prepareForSegue
。
关于ios - 应用程序尝试使用 Storyboard以模态方式呈现事件 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21858426/