[英]Getting nil while performing UIAlertController
我在ViewController中执行UIAlertViewController时遇到问题。
这是我目前所拥有的
func displayLoginResult(viewModel: Login.PerformLogin.ViewModel) {
endLoader(loader: loaderLogin)
if let errorMessage = viewModel.displayedError {
print(errorMessage.message)
let alert = UIAlertController(title: "Error", message: "Enter data in Text fields", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
else {
router.navigateToGroupsScene()
}
}
我试过删除DerivedData,但什么也没删除。 我只是考虑viewModel.displayedError不为nil的情况(不是else情况,只是if)。 我看过我是否评论此行:
self.presentViewController(alert, animated: true, completion: nil)
所有的作品,但显然任何对话框不是我想要的。 由于我从来没有遇到过这样的问题,所以我有点麻烦,而Xcode却为我提供了很多信息。
您需要任何其他信息,请让我知道,我会为您提供!
非常感谢。
您似乎忘记了删除观察者,请将以下代码添加到LoginViewController类中:
override func viewDidDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
您能否尝试使用以下代码:
func displayLoginResult(viewModel: Login.PerformLogin.ViewModel) {
endLoader(loader: loaderLogin)
if let errorMessage = viewModel.displayedError {
print(errorMessage.message)
let alert = UIAlertController(title: "Error", message: "Enter data in Text fields", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.presentViewController(alert, animated: true, completion: nil)
})
}
else {
router.navigateToGroupsScene()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.