2016-08-30 2 views
0

Я хотел бы представить последовательные контрольные контроллеры , начиная с действия с первого контроллера Alert в Swift.Последовательные UIAlertControllers - IOS - Swift

Так сценарий заключается в следующем:

1) Alert_A представлена ​​с 2-х вариантов:

  • а) Present Alert_B также уволить Alert_A после выбора этой опции

  • б) Present Alert_C также отклонить Alert_A после выбора этой опции

2) Alert_B/Alert_C будет иметь 2 варианта: каждый

  • а) Действие Alert_B/Действие Alert_C

  • б) Отмена увольняет 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

Спасибо @ Карло, он работает –

Смежные вопросы