Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 当前视图控制器错误_Objective C_Xcode_Cocoa Touch - Fatal编程技术网

Objective c 当前视图控制器错误

Objective c 当前视图控制器错误,objective-c,xcode,cocoa-touch,Objective C,Xcode,Cocoa Touch,在我的故事板中,我有两个UIViewController。初始视图控制器是一个显示简单图像的加载/启动屏幕。第二个视图控制器是UIWebView 我正在尝试在应用程序完全加载后用UIWebView视图控制器替换加载视图控制器 在我的加载视图控制器中,我有以下代码来显示UIWebView: UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *viewCo

在我的故事板中,我有两个UIViewController。初始视图控制器是一个显示简单图像的加载/启动屏幕。第二个视图控制器是UIWebView

我正在尝试在应用程序完全加载后用UIWebView视图控制器替换加载视图控制器

在我的加载视图控制器中,我有以下代码来显示UIWebView:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"WebView"];

[self presentViewController:viewController animated:NO completion:^(void){}];
但是,此代码会引发以下错误:

Warning: Attempt to present <WebController: 0x145617960> on <LoadingController: 0x145610c40> whose view is not in the window hierarchy!
警告:尝试显示其视图不在窗口层次结构中的对象!
我做错什么了吗


感谢您的帮助/建议。

如果您的代码块:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"WebView"];

[self presentViewController:viewController animated:NO completion:^(void){}];
在加载视图控制器时调用的加载视图控制器的方法中,例如
viewdiload
viewdide:
,或任何类似方法,问题是因为您的web视图控制器没有要显示的内容,
presentViewController
中的
self
指的是加载视图控制器。我的建议是将它放在加载视图控制器的
视图显示:
中,并在一秒钟后发送,以确保加载视图控制器能够实际显示它

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"WebView"];

    [self presentViewController:viewController animated:NO completion:^(void){}];
});
也许这就是解决办法