2016-08-30 1 views
0

アラートコントローラは、Swiftの最初のアラートコントローラからのアクションで始まります。連続するUIAlertControllers - IOS - Swift

ので、シナリオはこれです:

1)Alert_Aは、2つのオプションが提示されます。a)本Alert_Bも、このオプション

  • Bを選択した後Alert_Aを解任

    • )プレゼントAlert_Cこのオプションを選択するとAlert_Aも却下されます

    2)Alert_B/Alert_C 2つのオプションそれぞれを持っています:

    • a)のアクションAlert_B /アクションAlert_C

    • b)の解任をキャンセルAlert_B/Alert_C私が読んだ

    警告の中に警告を表示することは推奨されていません。

    私はまた、アラートの階層へのリンクを追加しました:

    Alert Diagram

  • +0

    あなたは何を投稿することができますこれまでに試したコードですか? 'UIAlertController'のドキュメントを見ましたか?具体的には 'UIAlertAction'ですか?ここでそれについての素晴らしいチュートリアルです:http://nshipster.com/uialertcontroller/ – random

    答えて

    1

    はこれで試してみてください:

    let alertController = UIAlertController(title: "Choose", message: "Choose one of two alert options", preferredStyle: UIAlertControllerStyle.Alert) 
         let Alert1 = UIAlertAction(title: "Alert1", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in 
    
    let alertController = UIAlertController(title: "Alert1", message: "You chose Alert1", preferredStyle: UIAlertControllerStyle.Alert) 
         let Action1 = UIAlertAction(title: "Action1", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in 
          /////////YOUR Action1//////// 
         } 
         let CancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (result : UIAlertAction) -> Void in 
         } 
    
         alertController.addAction(Action1) 
         alertController.addAction(CancelAction) 
    
    
        self.presentViewController(alertController, animated: true, completion: nil) 
         } 
         let Alert2 = UIAlertAction(title: "Alert2", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in 
    
    let alertController = UIAlertController(title: "Alert2", message: "You chose Alert2", preferredStyle: UIAlertControllerStyle.Alert) 
         let Action2 = UIAlertAction(title: "Action2", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in 
          /////////YOUR Action2//////// 
         } 
         let CancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (result : UIAlertAction) -> Void in 
         } 
    
         alertController.addAction(Action2) 
         alertController.addAction(CancelAction) 
        self.presentViewController(alertController, animated: true, completion: nil) 
    } 
    
    
          alertController.addAction(Alert1) 
          alertController.addAction(Alert2) 
    self.presentViewController(alertController, animated: true, completion: nil) 
    

    より良い方法:

    let alertController = UIAlertController(title: "Choose", message: "Action1 or Action2?", preferredStyle: UIAlertControllerStyle.Alert) 
        let Action1 = UIAlertAction(title: "Action1", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in 
         ///////Action1/////// 
        } 
        let Action2 = UIAlertAction(title: "Action2", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in 
         //////Action2/////// 
        } 
        let CancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (result : UIAlertAction) -> Void in 
        } 
    
        alertController.addAction(Action1) 
        alertController.addAction(Action2) 
    
    
         alertController.addAction(CancelAction) 
    
    self.presentViewController(alertController, animated: true, completion: nil) 
    
    +0

    @マイケル - それは働いた? –

    +0

    はい、それは完全に動作します – Carlo

    +0

    ありがとう@カルロ、それは動作します –

    関連する問題