2016-12-30 37 views
0

我在ViewController中执行UIAlertViewController时出现问题。在执行UIAlertController时出现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)) 
     self.presentViewController(alert, animated: true, completion: nil) 
    } 
    else { 
     router.navigateToGroupsScene() 
    } 
} 

我已经试过删除DerivedData但没有。我只是考虑viewModel.displayedError不是零的情况(不是其他情况,只是如果)。我已经看到了,如果我评论这一行:

self.presentViewController(alert, animated: true, completion: nil)

所有的作品,但显然任何对话框,显示这不是我想要的。我有点沮丧,因为我从来没有像这样的问题,Xcode提供了我没有太多的信息。

异常上的Xcode: enter image description here

线程的详细信息: enter image description here

您需要任何进一步的信息,只是让我知道,我会为您提供!

非常感谢。

+0

你是什么'self'?那是'无'吗? – Tj3n

回答

0

您似乎忘记删除观察员,将此代码添加到您的LoginViewController类:

override func viewDidDisappear(animated: Bool) { 
    NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil) 
    NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil) 
} 
+0

非常感谢你,这并不能解决我的错误,但是现在我可以从错误中看到,如果我想显示带有键盘的对话框显示原因为零,但是如果我隐藏键盘对话框显示。谢谢,现在我只需要调试为什么会发生这种情况!我已经标记你的答案是正确的,因为它与解决方案近似一样:)祝你有美好的一天! – Eironeia

0

能否请您尝试使用下面的代码:

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() 
    } 
} 
+0

感谢您的回复,但我已经尝试过,并且不起作用。奥雷斯特从错误出现的地方给我,现在我只需要找到它们。但问题是关于键盘观察者。无论如何谢谢你! – Eironeia

+0

多数民众赞成在亚历克斯 –