斯威夫特:在解雇的完成处理程序中呈现 VC



我有以下视图控制器(VC(流程:

启动画面/启动 VC -> 登录 VC(收到通知,存在(-> 启动画面VC ->主 VC

我想避免使用展开 segue,因为无论当前 VC 如何,我都需要定期重新验证用户,因此宁愿以编程方式"存在"。

问题是,我能够呈现和关闭启动画面 VC(最初是根(,但随后无法对登录 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!

如果我不关闭登录VC,代码运行良好,但我想随着时间的推移避免残留控制器。

我试图从顶级VC而不是"自我"来呈现,但这似乎并没有改变任何事情。

任何帮助将不胜感激。

由于错误表明您需要提供当前已关闭的 1 中的 vc,因此请改为

self.dismiss(animated: true, completion: {
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = loginVC
}

另一种方法是将rootVC嵌入到导航控制器中并执行

self.navigationController?.setViewControlls([loginVC],animated:true)

相关内容

  • 没有找到相关文章

最新更新