gpt4 book ai didi

ios - 连续的 UIAlertControllers - IOS - Swift

转载 作者:行者123 更新时间:2023-11-28 16:14:43 25 4
gpt4 key购买 nike

我想展示一个连续的 Alert Controllers,从 Swift 中第一个 Alert Controller 的一个 Action 开始。

所以场景是这样的:

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 文档中读到不建议在警报中显示警报。

我还添加了一个指向警报层次结构的链接:

Alert Diagram

最佳答案

试试这个:

 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)

关于ios - 连续的 UIAlertControllers - IOS - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39235814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com