【问题标题】:Application tried to present modally an active controller using storyboard应用程序尝试使用情节提要以模态方式呈现活动控制器
【发布时间】:2014-03-18 11:33:00
【问题描述】:

我正在使用故事板开发第一个教程,我的要求是我有两个文本字段和一个按钮。当我单击按钮时,如果文本字段不为空,我想将 V1Controller 导航到 V2Controller。为此,我从 V1Controller 拖到 V2Controller 并给出样式“模型”,我的标识符是 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”而终止应用程序,原因:“应用程序试图以模态方式呈现活动控制器。

提前致谢

【问题讨论】:

    标签: ios iphone storyboard


    【解决方案1】:

    在您的情况下,您不应在 prepareForSegue 内调用 presentViewController。这就是框架为你做的事情。

    如果你想用一些数据加载destinationViewController,应该使用prepareForSegue,例如。

    【讨论】:

    • 感谢兄弟的快速响应我只是删除了以下代码 SecondViewController *sVC =segue.destinationViewController; [自我presentViewController:sVC动画:是完成:否];现在工作正常
    • 我还有一个问题。我正在将 navigationController 添加到 V1Controller,例如 Editor----> EmbededIn--->NavigationController。如何使用相同的 navigationController 到 V2Controller
    • 我可以告诉你该怎么做,但对你来说最好的是阅读这样的简短教程:appcoda.com/…,你还有更多。祝你好运!
    • 再次感谢兄弟的建议
    猜你喜欢
    • 2013-01-06
    • 2011-12-25
    • 1970-01-01
    • 2014-03-03
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2020-06-06
    相关资源
    最近更新 更多