ios - 应用程序尝试使用 Storyboard以模态方式呈现事件 Controller

标签 ios iphone storyboard

我正在使用 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/

相关文章:

ios - 在 iOS 8 上使用 swift 设置占位符文本颜色/隐藏取消按钮

ios - 如何识别手指何时离开屏幕?

iphone - 谁动了我的看法?

wpf - 使用 StaticResource 作为 VisualTransition 的 Storyboard 时出错

ios - 如何在 Storyboard中使用 xib 文件作为自定义 View

ios - 分发 Passkit 通行证

ios - 此实现中的 UIPickerView 文本颜色更改

iphone - 设置在 Interface Builder 中通过代码创建的 UIButton 图像

iphone - 核心数据是否实现了数据映射器模式?

ios - 我的自定义 UITableViewCell 中的对象(使用 Storyboard创建)为零