2016-07-29 13 views
0

Im Folgenden sind die Codezeilen aufgeführt, die ich in swift (Xcode) zum Erstellen eines Popups verwende.Controller-Navigation anzeigen/Übergang über POP UP-Aktionsschaltfläche (UIAlertAction)

//create the alert 

let alert=UIAlertController(title: "Better Luck Next Time", message: "Try Again Later", preferredStyle: UIAlertControllerStyle.Alert) 

// add an action (button) 
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 

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

Sobald der Benutzer die OK-Taste im Popup-Menü drückt; Ich möchte, dass die App zu einem anderen View-Controller navigiert. Ich weiß, dass ich einige Codezeilen in den Handler-Teil von UIAlertAction schreiben muss. Aber ich bin mir nicht sicher, wie ich diesen Übergang programmieren soll. Jeder hat irgendwelche einfachen und effektiven Ideen ??.

Antwort

0
let alertController = UIAlertController(title: "Default AlertController", message: "A standard alert", preferredStyle: .Alert) 

      let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action:UIAlertAction!) in 
       println("you have pressed the Cancel button"); 
      } 
      alertController.addAction(cancelAction) 

      let OKAction = UIAlertAction(title: "OK", style: .Default) { (action:UIAlertAction!) in 
       println("you have pressed OK button"); 
       if let navController = self.navigationController 
       { 
          navController.popViewControllerAnimated(true) 
       } 
      } 
      alertController.addAction(OKAction) 


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