gpt4 book ai didi

ios - 警告 : Attempt to present * on * whose view is not in the window hierarchy - swift

转载 作者:IT王子 更新时间:2023-10-29 04:57:22 27 4
gpt4 key购买 nike

我正在尝试呈现一个 ViewController 如果数据模型中有任何已保存的数据。但是我收到以下错误:

Warning: Attempt to present * on *whose view is not in the window hierarchy"

相关代码:

override func viewDidLoad() {
super.viewDidLoad()
loginButton.backgroundColor = UIColor.orangeColor()

var request = NSFetchRequest(entityName: "UserData")
request.returnsObjectsAsFaults = false

var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!

var results:NSArray = context.executeFetchRequest(request, error: nil)!

if(results.count <= 0){
print("Inga resultat")
} else {
print("SWITCH VIEW PLOX")
let internVC = self.storyboard?.instantiateViewControllerWithIdentifier("internVC") as internViewController
self.presentViewController(internVC, animated: true, completion: nil)
}
}

我尝试过使用 Google 发现的不同解决方案,但均未成功。

最佳答案

此时在您的代码中, View Controller 的 View 仅已创建,但尚未添加到任何 View 层次结构中。如果您想尽快从该 View Controller 中呈现,您应该在 viewDidAppear 中进行,以确保最安全。

关于ios - 警告 : Attempt to present * on * whose view is not in the window hierarchy - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26022756/

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