手动模态segue不起作用,View Controller不在窗口层次结构中?

blu*_*din 10 ios ios5 uistoryboard uistoryboardsegue ios6

我一直在网上搜索Stack Overflow几个小时,我无法解决这个问题.这里希望你们都看到我的错误,因为我找不到它.

我刚开始有一个简单的基于故事板的应用程序.最初的ViewController是UITabBarController的一个实例,它带有来自模板的两个虚拟ViewControllers.启动时,我需要检查设备是否已登录到外部服务.如果没有,我将显示一个允许用户进行身份验证的模态ViewController,如果设备已经过身份验证,那么我将只显示FirstViewController.

以下步骤是自创建项目以来我所做的一切:

  1. 在Storyboard上创建AuthenticateViewController场景
  2. 为AuthenticateViewController创建代码文件,并将它们分配给相应的场景
  3. 为UITabBarController子类创建代码文件,并将初始UITabBarController场景与该新子类关联
  4. 在故事板上从UITabBarController场景到AuthenticateViewController场景创建一个新的segue
  5. viewDidLoadUITabBarController子类中手动调用segue

当我运行应用程序时,模态segue不会触发,显示UITabBarController的第一个ViewController,我在XCode中得到以下输出:

Warning: Attempt to present <AuthenticateViewController: 0x83c0c10> on <EPTabBarController: 0x83be600> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

下面的相关代码,实际上是我到目前为止添加的唯一代码.如果截图或其他信息有用,请告诉我.在此先感谢您的帮助.

EPTabBarController,UITabBarController的子类:

#import "EPTabBarController.h"
#import "AuthenticateViewController.h"

@interface EPTabBarController ()

@end

@implementation EPTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self performSegueWithIdentifier:@"authenticationSegue" sender:self];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Run Code Online (Sandbox Code Playgroud)

βha*_*avḯ 14

问题出在里面

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self performSegueWithIdentifier:@"authenticationSegue" sender:self];
}
Run Code Online (Sandbox Code Playgroud)

您正在尝试在窗口层次结构中尚未加载AuthenticateViewController当前视图()时呈现另一个视图()EPTabBarController.

首先让你EPTabBarController在窗口层次结构中加载然后呈现AuthenticateViewController.

试一试

- (void)viewDidLoad 
{
    [super viewDidLoad];        
    [self performSelector:@selector(loadAuthenticateViewController) 
               withObject:nil 
               afterDelay:1.0];
}

-(void)loadAuthenticateViewController 
{
    [self performSegueWithIdentifier:@"authenticationSegue" sender:self];
}
Run Code Online (Sandbox Code Playgroud)