2016-12-30 6 views
0

ViewControllerでUIAlertViewControllerを実行する際に問題が発生しました。UIAlertControllerを実行中にnilを取得する

これは、私は現在、私はDerivedData何も削除しようとしました

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

を持っているものです。私はviewModel.displayedErrorがnilではないケースを考慮しています(elseケースではなく、ifだけ)。

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

すべての作品をしかし、明らかに任意のダイアログは、私が欲しいものではありませんどの表示されます。私は、この行をコメント場合見てきました。私はこのような問題は一度もなかったので、少し欲求不満で、Xcodeは私にあまり情報を提供しません。 Xcodeの上

例外: enter image description here

スレッドの詳細: enter image description here

あなたが必要な任意の更なる情報、ちょうど私が知っていると私はあなたを提供します!

ありがとうございました。あなたはLoginViewControllerクラスにこのコードを追加し、オブザーバを削除するのを忘れたよう

+0

?それは「なし」ですか? – Tj3n

答えて

0

はルックス:

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

ありがとうございます、これは私のエラーを解決しませんが、私はエラーから来て、私は原因のnilを表示するキーボードでダイアログを表示したい場合が表示されますが、ありがとう、今私はちょうどこれがなぜ起こるかデバッグする必要がありました!私は解決策に近づくのであなたの答えに正しいと印を付けました:)素敵な一日を! – Eironeia

0

あなたは、コードの下に使用してみてくださいでした:あなた `self`は何

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

thats nice alex –

関連する問題