gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 11:00:01 25 4
gpt4 key购买 nike

我已经在网络和 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com