无法在UIAlertController中选择按钮的顺序 [英] Unable to choose order of buttons in UIAlertController

查看:343
本文介绍了无法在UIAlertController中选择按钮的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是,如果正常操作是破坏性操作而另一个是UIAlertController中的取消操作,则破坏性操作应位于左侧,取消应位于右侧。

I was under the impression that if the normal action is a destructive action and the other is a cancel action in their UIAlertController that the destructive one should be on the left and the cancel should be on the right.

如果正常行动不是破坏性的,则正常行动应在右侧,取消应在左侧。

If the normal action is not destructive, then the normal action should be on the right and the cancel should be on the left.

那就是说,我有以下内容:

That said, I have the following:

var confirmLeaveAlert = UIAlertController(title: "Leave", message: "Are you sure you want to leave?", preferredStyle: .Alert)

let leaveAction = UIAlertAction(title: "Leave", style: .Destructive, handler: {
        (alert: UIAlertAction!) in

        //Handle leave

    }
)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)

confirmLeaveAlert.addAction(leaveAction)
confirmLeaveAlert.addAction(cancelAction)

self.presentViewController(confirmLeaveAlert, animated: true, completion: nil)

我的印象是如果我添加 leaveAction 首先,然后 cancelAction leaveAction 将是左边的按钮。此情况并非如此。我也尝试按相反的顺序添加按钮,这也导致按钮以相同的顺序添加。

I was under the impression that if I add the leaveAction first, then the cancelAction that the leaveAction would be the button on the left. This was not the case. I tried adding the buttons in the opposite order as well and it also resulted in the buttons being added in the same order.

我错了吗?有没有办法实现这个目标?

Am I wrong? Is there no way to achieve this?

推荐答案

我的解决办法是使用 .Default 样式而不是 .Cancel 代表 cancelAction

My solution to this was to use the .Default style instead of .Cancel for the cancelAction.

这篇关于无法在UIAlertController中选择按钮的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆