Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UIAlertController-操作顺序_Swift_Uialertcontroller - Fatal编程技术网

Swift UIAlertController-操作顺序

Swift UIAlertController-操作顺序,swift,uialertcontroller,Swift,Uialertcontroller,我想通过按下按钮来显示警报窗口。平常的事。但我感到困惑的是,我一开始试图显示按钮“棒极了”,但总是先显示“取消”按钮。我怎样才能修好它 let alert = UIAlertController(title: "Hello world", message: "Testing", preferredStyle: .alert) let action = UIAlertAction(title: "Awesome", style: .default){(_) in print("Awesome")}

我想通过按下按钮来显示警报窗口。平常的事。但我感到困惑的是,我一开始试图显示按钮“棒极了”,但总是先显示“取消”按钮。我怎样才能修好它

let alert = UIAlertController(title: "Hello world", message: "Testing", preferredStyle: .alert)
let action = UIAlertAction(title: "Awesome", style: .default){(_) in print("Awesome")}
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

alert.addTextField(configurationHandler: nil)
alert.addAction(action)
alert.addAction(cancel)

alert.actions.forEach( { (action) in print( action.title! ) } )

present(alert, animated: true, completion: nil)

像这样试试,它会对你有用的

let alertController = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.alert)
let destructiveAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default) {
    (result : UIAlertAction) -> Void in
}
let okAction = UIAlertAction(title: "Awesome", style: UIAlertActionStyle.default) {
    (result : UIAlertAction) -> Void in

}
alertController.addAction(destructiveAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)

像这样试试,它会对你有用的

let alertController = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.alert)
let destructiveAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default) {
    (result : UIAlertAction) -> Void in
}
let okAction = UIAlertAction(title: "Awesome", style: UIAlertActionStyle.default) {
    (result : UIAlertAction) -> Void in

}
alertController.addAction(destructiveAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)

更改订单将不起作用,因为“取消”按钮的默认位置已保留


将取消按钮类型的操作样式更改为UIAlertActionStyleDefault,而不是UIAlertActionStyleCancel。

更改顺序将不起作用,因为取消按钮的默认位置已保留


将取消按钮类型的操作样式更改为UIAlertActionStyleDefault,而不是UIAlertActionStyleCancel。

您是否尝试过更改这些语句的顺序:alert.addAction(action)alert.addAction(cancel),如果它不起作用,那么我猜UIAlertController的默认行为是将取消操作置于leftyeah,我试过这个你试过改变这些语句的顺序吗:alert.addAction(action)alert.addAction(cancel),如果它不起作用,那么我猜UIAlertController的默认行为是将取消操作放在左边是的,我试过这个“cancel”不是破坏性的操作。这是一个糟糕的变量名称。更不用说变量名应该以小写字母开头。好吧,我改了,看我的答案@rmaddy“Cancel”不是破坏性的行为。这是一个糟糕的变量名称。更不用说变量名应该以小写字母开头了。好吧,我改了,看我的答案@rmaddyThx,它可以工作。但是我仍然不明白按钮的.default和.cancel样式之间的区别)Thx,它可以工作。但我仍然不理解按钮的.default和.cancel样式之间的区别)