2016-06-16 10 views
0

こんにちは私はユーザーがokアクションボタンをUIAlertViewでクリックした後、他のコントローラにリダイレクトしています。 [OK]を、私はエラーSWRevealViewControllerが予期せずnilが見つかりました。オプション値をアンラッピングしています

override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated); 


     self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer()) 
     if revealViewController() != nil { 
      menuButton.target = self.revealViewController() 
      menuButton.action = "revealToggle:" 
      view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) 
     } 
} 

をリダイレクトしていますsecondViewControllerにここでエラーを取得していますクリックした後

 let successAlert = UIAlertController(title: "Success", message: Message.TRIPISLIVE, preferredStyle: UIAlertControllerStyle.Alert) 

      let action = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in 
      let viewControllerYouWantToPresent = self.storyboard?.instantiateViewControllerWithIdentifier("MyTripsTableViewController") 
    self.presentViewController(viewControllerYouWantToPresent!, animated: true, completion: nil) 
      } 
successAlert.addAction(action) 
self.presentViewController(successAlert, animated: true, completion: nil) 

致命的なエラーです:

答えて

1

できるオプションの値をアンラップしながら、予想外にnilを見つけコードの代わりにこれを試してくださいviewWillAppear

override func viewWillAppear(animated: Bool) { 
      super.viewWillAppear(animated); 

      if revealViewController() != nil { 
       self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer()) 
       menuButton.target = self.revealViewController() 
       menuButton.action = "revealToggle:" 
       self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) 
      } 
    } 
あなたがそうこれを入れて、あなたがあなたの viewControllerYouWantToPresentを現在の形を変更する必要があなたの viewController

func customLeftButtonAction() { 
     self.revealViewController().revealToggleAnimated(true); 
    } 

にこのようなfuncを追加し

override func viewWillAppear(animated: Bool) { 
       super.viewWillAppear(animated); 

       if revealViewController() != nil { 
        self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer()) 
        menuButton.target = self 
        menuButton.action = #selector(self.customLeftButtonAction) 
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) 
       } 
     } 

Edited

を変更することができます

EDITED

代わりにコード

let successAlert = UIAlertController(title: "Success", message: Message.TRIPISLIVE, preferredStyle: UIAlertControllerStyle.Alert) 

      let action = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in 
      let viewControllerYouWantToPresent = self.storyboard?.instantiateViewControllerWithIdentifier("MyTripsTableViewController") 
    self.revealViewController().setFrontViewController(viewControllerYouWantToPresent!, animated: false); 
    self.revealViewController().revealToggleAnimated(true); 
      } 
successAlert.addAction(action) 
self.presentViewController(successAlert, animated: true, completion: nil) 

私は、はい、それは感謝の作品..しかし、問題は、今のメニューのハンバーガーボタンは、このコントローラにはもう働いていないされ、これはあなた

+0

に役立ちます願っています。 – hellosheikh

+0

私の答えは –

+0

に更新されました。完全なコードを書いてください。私は新しいですので、私はそこに何を書くべきか分かりません – hellosheikh

関連する問題