gpt4 book ai didi

ios - 尝试呈现其 View 不在窗口层次结构中的 UINavigationController! ( swift )

转载 作者:行者123 更新时间:2023-11-30 11:21:13 24 4
gpt4 key购买 nike

我遇到了 View Controller 未显示的问题,即使调用 View Controller 的函数似乎正在运行。我在控制台中收到的错误是:

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

我已经尝试了“尝试在 View 不在窗口层次结构中的 UIViewController 上呈现 UIViewController”线程的建议,但没有任何进展。我正在以编程方式运行一切。

func handleNewPage(){
print("this code works")
let uid = Auth.auth().currentUser?.uid

ref = Database.database().reference()

let usersReference = ref.child("patient").child((uid)!)

if usersReference.child("Doctor Code") != nil {
func presentNewPage(){
let firstPage = LandingPage()
let navCon = UINavigationController(rootViewController: firstPage)
present(navCon, animated: true, completion: nil)

}
presentNewPage()
print("PRINT")
} else{
let newPage = PresentViewController() // doctor reg page
let navController = UINavigationController(rootViewController: newPage)
present(navController, animated: true, completion: nil)
}
}

该函数被调用并且打印语句有效。然而, View Controller 不会出现。

最佳答案

你必须在你的if之外创建presentNewPage()函数???

if usersReference.child("Doctor Code") != nil {
func presentNewPage(){
let firstPage = LandingPage()
let navCon = UINavigationController(rootViewController: firstPage)
present(navCon, animated: true, completion: nil)

}
presentNewPage()
print("PRINT")
} else{
let newPage = PresentViewController() // doctor reg page
let navController = UINavigationController(rootViewController: newPage)
present(navController, animated: true, completion: nil)
}

这样改

func presentNewPage(){
let firstPage = LandingPage()
let navCon = UINavigationController(rootViewController: firstPage)
present(navCon, animated: true, completion: nil)

}

func handleNewPage(){
print("this code works")
let uid = Auth.auth().currentUser?.uid

ref = Database.database().reference()

let usersReference = ref.child("patient").child((uid)!)

if usersReference.child("Doctor Code") != nil {

presentNewPage()
print("PRINT")
} else{
let newPage = PresentViewController() // doctor reg page
let navController = UINavigationController(rootViewController: newPage)
present(navController, animated: true, completion: nil)
}
}

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

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