从appdelegate执行segue

时间:2013-01-06 11:22:52

标签: objective-c cocoa-touch uiwebview appdelegate

我有以下代码:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //make sure that the user credentials are still ok
    if (userLeftApplication){
        BaseViewController * baseViewController = [[BaseViewController alloc]init];
        BOOL detailsAreOK = [baseViewController credentialsValidated];
        if (!detailsAreOK){
            [self.window.rootViewController performSegueWithIdentifier: @"fromSplashToLogin" sender: self.window.rootViewController];
        }
        userLeftApplication = FALSE;
    }
}

但是,在尝试执行segue时出现以下异常:

Attempt to present <LoginViewController: 0x2012e180> on <FirstViewController: 0x1f59cef0> whose view is not in the window hierarchy!

并且用户没有被定向到那里。

有什么问题?

1 个答案:

答案 0 :(得分:2)

当前未定义rootViewController。你不能“从App Delegate执行segue”,segues是视图控制器之间的转换。您需要启动视图控制器而不是执行segue。

self.window.rootViewController = baseViewController;