【发布时间】:2018-06-18 14:01:50
【问题描述】:
我想在应用启动时在 AppDelegate 中的 rootViewController 上显示 alertViewController。这里sn-p的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let alert: UIAlertController = UIAlertController(title: "This is title", message: "This is message.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
return true
}
警报未出现在 rootViewController 上。请帮帮我。
【问题讨论】:
-
window有值还是 nil?rootViewController的同样问题。 -
检查windowLevel并使其等于UIWindowLevelAlert
-
window 和 rootViewController 不为零。
标签: ios swift appdelegate uialertviewcontroller