【发布时间】:2022-01-01 17:59:29
【问题描述】:
我在我的 IOS 应用程序中显示视图控制器时遇到了一些问题。 有时它可以工作并显示视图,但有时我猜当上下文有点不同时它不会工作。调试器中没有错误或警告,它可以从主情节提要中找到 ViewController(至少它不是 nil) 它曾经与 self.present 一起使用,但似乎不再适用了。
@IBAction func showHistoryButton(_ sender: MDCButton) {
let exercisesHistoryVC = ExercisesHistoryViewController.instantiate(from: .Main)
exercisesHistoryVC.modalPresentationStyle = .fullScreen
let appDeligate = UIApplication.shared.delegate as! AppDelegate
appDeligate.window?.rootViewController!.present(exercisesHistoryVC,animated: true,completion: nil)
// parent?.present(exercisesHistoryVC, animated: true, completion: nil)
}
【问题讨论】:
-
应该是
self.present? -
如果视图控制器已经在呈现某些东西,它将无法工作。当演示不工作时,我会先检查视图层次结构。
-
这确实已经是层次结构中的 3e 屏幕,所以这可能是问题所在。是否可以始终在所有内容之上呈现此视图控制器?
标签: swift xcode storyboard