当我离开特定的 View Controller 时,我想让它在导航堆栈中的前一个 View 上显示一个模态视图。目前我正在使用以下代码执行此操作:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.viewControllers.last?.present(myModalView, animated: false, completion: nil)
}
这似乎有效,但每次我离开 View 时,我都会在控制台中收到警告:
Presenting view controllers on detached view controllers is discouraged <Project.MyViewController: 0x7fe09281a400>.
所以我担心可能存在我尚未遇到的问题。有“正确”的方法吗?
最佳答案
事实证明,self.present(myModalView,animated: false,completion: nil)
工作完美,没有任何警告。回想起来,我可能应该先测试一下,但我认为它不会起作用,因为 View 正在消失。
此外,它根本不与animated: true
一起工作,而我原来的解决方案可以没有任何警告(但我不这样做)不希望它被动画化)。不确定这是否只是异步进程的工作原理,或者是否还有更多内容。
关于swift - 过渡到上一个 View 时呈现模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50475826/