2016-07-29 4 views
0

以下は、ポップアップを作成するためにswift(Xcode)で使用しているコード行です。コントローラのナビゲーション/ POP UPアクションボタン(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) 

ユーザーがポップアップメニューの[OK]ボタンを押すと、私は、別のビューコントローラに移動するアプリをします。私はUIAlertActionのハンドラ部分にいくつかのコード行を入れなければならないことを知っています。しかし、私はどのようにこの移行をコード化するのか分かりません。誰にでも簡単で効果的なアイデアがありますか?

答えて

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) 
関連する問題