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

标签 ios ios5 ios6 uistoryboard uistoryboardsegue

我已经在网络和 Stack Overflow 上搜索了几个小时,但我无法解决这个问题。希望你们都能看到我的错误,因为我就是找不到它。

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

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

  1. 在 Storyboard 上创建 AuthenticateViewController 场景
  2. 为AuthenticateViewController创建代码文件,并赋值给相应的场景
  3. 为 UITabBarController 子类创建代码文件,并将初始 UITabBarController 场景关联到该新子类
  4. 在 Storyboard上创建一个从 UITabBarController 场景到 AuthenticateViewController 场景的新转场
  5. 从 UITabBarController 子类中的 viewDidLoad 手动调用 segue

当我运行应用程序时,模式转场没有触发,显示了 UITabBarController 的第一个 ViewController,我在 XCode 中得到以下输出:

Warning: Attempt to present <AuthenticateViewController: 0x83c0c10> on <EPTabBarController: 0x83be600> whose view is not in the window hierarchy!

下面的相关代码,实际上是我到目前为止添加的唯一代码。请让我知道屏幕截图或其他信息是否有用。预先感谢您的帮助。

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

最佳答案

问题在里面

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self performSegueWithIdentifier:@"authenticationSegue" sender:self];
}

您正在尝试呈现另一个 View (AuthenticateViewController),而您的当前 View (EPTabBarController)尚未加载到窗口层次结构中。

因此,首先让您的 EPTabBarController 加载到窗口层次结构中,然后呈现 AuthenticateViewController

试一试

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

-(void)loadAuthenticateViewController 
{
    [self performSegueWithIdentifier:@"authenticationSegue" sender:self];
}

关于ios - 手动模态 segue 不起作用,View Controller 不在窗口层次结构中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15607821/

相关文章:

ios - 动画约束更改不起作用

ios - Swift:从 Storyboard 中控制拖动最终出现在错误的位置

ios - 变换旋转后定位 View

xcode4 - 我如何将 excel 文件类型 (xlsx) 与 iPhone 应用程序相关联

ios - iOS5 中的 AVCaptureSession 预览屏幕方向

ios - 在 iOS 中获取 wifi 路由器类型

ios - 错误 fmdb 设置 label.text

ios - 定义新接口(interface)会导致 "Undefined symbols for architecture x86_64:"。现有接口(interface)工作正常

第一次点击时未调用 UITableView didSelectRowAtIndexPath

iphone - 开始编辑时 Textview 无法向上移动