2016-06-16 12 views
0

Hallo Ich bin Benutzer auf einen anderen Controller umleiten, nachdem Benutzer auf OK Aktion Schaltfläche auf UIAlertView klickt.SWRevealViewController unerwartet gefunden Null beim Entpacken ein optionaler Wert

 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) 

nach ok klicken Ich erhalte Fehler hier im secondViewController, wo ich bin Umleitung

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

Der Fehler ist fataler Fehler: unerwartet gefunden Null, während ein optionaler Wert Abwickeln

Antwort

1

können Sie versuchen dies anstelle Ihres Codes für 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()) 
      } 
    } 

EDITED

können Sie eine func wie diese auf Ihrem viewController

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

hinzufügen und dann

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

Sie das Formular ändern müssen, modifizieren, dass Sie Ihre viewControllerYouWantToPresent so präsentieren diese setzen Code stattdessen

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) 

Ich hoffe, das hilft Ihnen

+0

ja Es funktioniert dank .. Aber das Problem ist jetzt das Menü Hamburger-Taste funktioniert nicht mehr auf diesem Controller. – hellosheikh

+0

meine Antwort wurde aktualisiert –

+0

Könnten Sie bitte einen vollständigen Code schreiben oder meins bearbeiten. Ich bin neu so verstehe nicht, was ich dort schreiben sollte – hellosheikh

Verwandte Themen