gpt4 book ai didi

iOS:切换到第二个 ViewController

转载 作者:行者123 更新时间:2023-11-29 12:05:19 25 4
gpt4 key购买 nike

我正在编写一个脚本,该脚本使用 Reachability 检查 Internet 连接。如果没有互联网,我希望它加载第二个 ViewController。这是我目前所拥有的:

-(BOOL) hasInternet {
Reachability *reach = [Reachability reachabilityWithHostName:@"http://www.google.com"];
NetworkStatus internetStatus = [reach currentReachabilityStatus];
if( internetStatus == NotReachable){
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:nil];
}else{

}
return YES;
}

我得到的错误是:

Attempt to present SecondViewController: 0x7ff780628d10 on ViewController: 0x7ff780719830 whose view is not in the window hierarchy!

谁能看出我哪里错了。

非常感谢您的帮助和时间。

最佳答案

You are attempting to present another viewController while first ViewController has yet not loaded.

解决方案:

  1. 在 viewDidAppear() 方法中调用您的函数。
  2. 写下你想要加载的View Controllers Nib Name

关于iOS:切换到第二个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35249094/

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