2016-08-30 69 views
0

我想通过Swift中第一个Alert Controller的动作开始连续提供报警控制器连续的UIAlertControllers - IOS - Swift

所以情况是这样的:

1)Alert_A呈现2种选择:

  • 一)当前Alert_B也选择此选项

  • B之后解雇Alert_A)当前Alert_C在选择此选项后也关闭Alert_A

2)Alert_B/Alert_C将各有2种选择:

  • 1)作用Alert_B /动作Alert_C

  • b)取消驳回Alert_B/Alert_C

我在读Apple文档建议不要在警报中显示警报。

我还添加了一个链接到警报的层次:

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

@mike - 它的工作? –

+0

是的,它完美的作品 – Carlo

+0

谢谢@Carlo,它的工作 –