【发布时间】:2020-01-12 23:02:45
【问题描述】:
我有以下 ViewController (VC) 流程:
SplashScreen/launch VC -> Login VC (on notification, present) -> SplashScreenVC -> Main VC
我想避免使用 unwind segue,因为无论当前的 VC 如何,我都需要定期重新验证用户身份,因此更愿意以编程方式“呈现”。
问题是,我可以展示和关闭 SplashScreen VC(它最初是根目录),但不能在没有错误的情况下对 Login VC 执行相同操作。
代码:
//in SplashScreen VC viewDidAppear
let loginVC = myStoryboard.instantiateViewController(identifier: "loginVC") as UIViewController
loginVC.modalPresentationStyle = .fullScreen
loginVC.modalTransitionStyle = .coverVertical
//dismissal?
self.dismiss(animated: true, completion: {
self.present(loginVC, animated: true, completion: nil)
})
//in loginVC selector function
let launchVC = myStoryboard.instantiateViewController(identifier: "launchVC") as UIViewController
launchVC.modalPresentationStyle = .fullScreen
launchVC.modalTransitionStyle = .coverVertical
//check for top view controller (debugging)
print("TOPVC at LoginVC: \(self.getTopVC()!)")
//handle dismissal?
self.dismiss(animated: true, completion: {
self.present(launchVC, animated: true, completion: nil)
})
警告:
Warning: Attempt to present <Slidr.LaunchScreenViewController: 0x15be0ef90> on <Slidr.LoginViewController: 0x15be6b510> whose view is not in the window hierarchy!
Warning: Attempt to present <Slidr.TestingViewController: 0x15db00ac0> on <Slidr.LaunchScreenViewController: 0x15bd06960> whose view is not in the window hierarchy!
如果我不关闭 loginVC,代码运行良好,但我想随着时间的推移避免残留控制器。
我试图从顶级 VC 而不是“自我”展示,但这似乎并没有改变任何东西。
任何帮助将不胜感激。
【问题讨论】:
标签: ios swift uiviewcontroller segue