gpt4 book ai didi

ios - 尝试在其 View 不在窗口层次结构中的 ViewController 上呈现

转载 作者:行者123 更新时间:2023-11-28 18:57:10 25 4
gpt4 key购买 nike

这是在主菜单上使用的代码,当用户按下播放键时,但是当显示该屏幕时 (ViewController.m) 它会显示错误

警告:尝试呈现不在窗口层次结构中的 View !

-(IBAction)play:(id)sender
{
if(IS_IPAD)
{
ViewController *view_obj = [[ViewController alloc]initWithNibName:@"ViewController_iPad" bundle:[NSBundle mainBundle]];
[self presentViewController:view_obj animated:YES completion:nil];

}
else if ([AISGlobal isIphone5thGeneration])
{
ViewController *view_obj = [[ViewController alloc]initWithNibName:@"ViewController_iPhone5" bundle:[NSBundle mainBundle]];
[self presentViewController:view_obj animated:YES completion:nil];


}
else
{
ViewController *view_obj = [[ViewController alloc]initWithNibName:@"ViewController_iPhone" bundle:[NSBundle mainBundle]];
[self presentViewController:view_obj animated:YES completion:nil];

}

}

在 AppDelegate.m 文件中,它在“didFinishLaunchingWithOptions”部分显示了这一点;

if(IS_IPAD)
{
self.start_screen_obj = [[Start_screen alloc] initWithNibName:@"Start_screen" bundle:nil];
}
else if ([AISGlobal isIphone5thGeneration])
{
self.start_screen_obj = [[Start_screen alloc] initWithNibName:@"Start_screen_iphone5" bundle:nil];

}
else
{
self.start_screen_obj = [[Start_screen alloc] initWithNibName:@"Start_screen_iphone" bundle:nil];
}

self.start_screen_obj.view.multipleTouchEnabled = YES;

self.window.rootViewController = self.start_screen_obj;

[self.window makeKeyAndVisible];

最佳答案

尝试在 View Controller 的 viewDidAppear 方法中编写您的代码,因为直到那时您的 View 才刚刚创建,并没有添加到 View 层次结构中。

关于ios - 尝试在其 View 不在窗口层次结构中的 ViewController 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31139515/

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