0

Swift の最初の Alert Controller からのアクションから始まる一連のAlert Controllerを提示したいと思います。

したがって、シナリオは次のとおりです。

1) Alert_A には 2 つのオプションが表示されます。

  • a) このオプションを選択した後、Alert_B を提示し、Alert_A も破棄します

  • b) このオプションを選択した後、Alert_C を表示して Alert_A も閉じる

2) Alert_B/Alert_C にはそれぞれ 2 つのオプションがあります。

  • a) アクション アラート_B/アクション アラート_C

  • b) キャンセルは Alert_B/Alert_C を無視します

アラート内にアラートを提示することは推奨されていないことをAppleのドキュメントで読みました。

アラートの階層へのリンクも追加しました。

アラート図

4

1 に答える 1

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)
于 2016-08-30T19:57:27.080 に答える