将 destructiveButtonTitle 移动到 UIActionSheet 的底部

Move destructiveButtonTitle to bottom of UIActionSheet

我希望将取消按钮移到操作表的底部,成为用户可以使用的最后一个按钮。我有这个代码:

func openImagePicker(
    actionSheetTitle:String="Choose Image Source",
    cancelTitle:String="Cancel",
    cameraTitle:String="Camera",
    galleryTitle:String="Gallery",
    isImage:Bool=true,
    isMultipleSelection:Bool=false,
    completeHandler:(success:Bool,arrAssert:[TCAsset])->Void,
    failurer:((error:String)->(Void))?=nil)
{

    let actionSheet=UIActionSheet(title: actionSheetTitle, delegate:self, cancelButtonTitle:nil, destructiveButtonTitle:cancelTitle,otherButtonTitles: cameraTitle, galleryTitle)

    if UIDevice.currentDevice().userInterfaceIdiom == .Phone
    {
        actionSheet.showInView(UIApplication.sharedApplication().keyWindow!)
    }
    else
    {
        let appDel = UIApplication.sharedApplication().delegate as? AppDelegate


        actionSheet.showInView((appDel?.window?.rootViewController?.view)!)
    }

当前显示的操作表如下:

如何才能使取消按钮成为列表中的最后一个按钮?

谢谢:)

我没有实现你的完成块,但这应该让你开始:

func openImagePicker(
        actionSheetTitle:String="Choose Image Source",
        cancelTitle:String="Cancel",
        cameraTitle:String="Camera",
        galleryTitle:String="Gallery",
        isImage:Bool=true,
        isMultipleSelection:Bool=false,
        completeHandler:(success:Bool,arrAssert:[Bool])->Void,
        failurer:((error:String)->(Void))?=nil)
    {
        let sheet = UIAlertController(title: actionSheetTitle, message: nil, preferredStyle: .ActionSheet)
        sheet.addAction(UIAlertAction(title: cameraTitle, style: .Default, handler: { _ in
            // Code to execute when "Camera" is pressed
            print("Camera selected")
        }))
        sheet.addAction(UIAlertAction(title: galleryTitle, style: .Default, handler: { _ in
            // Code to execute when "Gallery" is pressed
            print("Gallery selected")
        }))
        sheet.addAction(UIAlertAction(title: cancelTitle, style: .Destructive, handler: { _ in
            // Code to execute when "Cancel" is pressed
            print("Cancel selected")
        }))
        presentViewController(sheet, animated: true, completion: nil)
    }

该函数必须驻留在 UIViewController 的实例中(因为它将调用 presentViewController(....

我觉得对此有一个非常简单的答案:

您可以使用 destructiveButtonIndex 将 destructiveButton 的索引设置为您想要的任何位置。

actionSheet.destructiveButtonIndex = 2;