应用程序试图在其自身上呈现模态视图控制器
Application tried to present modal view controller on itself
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if userSignedInGlobal == "success"{
if let mainTabController = storyboard.instantiateViewController(withIdentifier: "MainTabController") as? MainTabController{
mainTabController.present(mainTabController, animated: true, completion: nil)
}
}
由于未捕获的异常 'NSInvalidArgumentException',正在终止应用程序,原因:'Application tried to present modal view controller on itself. Presenting controller is .'
我需要在使用 firebase 验证应用程序后导航到一个页面,以便在验证身份验证后使用上面的代码。我该如何解决这个问题?参考 link 或解释如何到达那里的代码就足够了。
如果您在 UIViewController 中,则更改此行:
self.present(mainTabController, animated: true, completion: nil)
如果您在 Appdelegate 中,则将您的 ViewController 设置为 window
属性:
的根视图控制器
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if userSignedInGlobal == "success"{
if let mainTabController = storyboard.instantiateViewController(withIdentifier: "MainTabController") as? MainTabController{
window?.rootViewController = mainTabController
window?.makeKeyAndVisible()
}
}
移除 之前 的控制器,而不是
mainTabController.present(mainTabController, animated: true, completion: nil)
仅使用:
present(mainTabController, animated: true, completion: nil)
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if userSignedInGlobal == "success"{
if let mainTabController = storyboard.instantiateViewController(withIdentifier: "MainTabController") as? MainTabController{
mainTabController.present(mainTabController, animated: true, completion: nil)
}
}
由于未捕获的异常 'NSInvalidArgumentException',正在终止应用程序,原因:'Application tried to present modal view controller on itself. Presenting controller is .'
我需要在使用 firebase 验证应用程序后导航到一个页面,以便在验证身份验证后使用上面的代码。我该如何解决这个问题?参考 link 或解释如何到达那里的代码就足够了。
如果您在 UIViewController 中,则更改此行:
self.present(mainTabController, animated: true, completion: nil)
如果您在 Appdelegate 中,则将您的 ViewController 设置为 window
属性:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if userSignedInGlobal == "success"{
if let mainTabController = storyboard.instantiateViewController(withIdentifier: "MainTabController") as? MainTabController{
window?.rootViewController = mainTabController
window?.makeKeyAndVisible()
}
}
移除 之前 的控制器,而不是
mainTabController.present(mainTabController, animated: true, completion: nil)
仅使用:
present(mainTabController, animated: true, completion: nil)