UIActionSheet in swift puts Cancel button top in iOS 7

后端 未结 2 1280
慢半拍i
慢半拍i 2021-01-17 12:10

I am in the process of rewriting my app from objective c to Swift and I noticed that UIActionSheet behaves differently in Swift version than in obj-c version.

Obj-c

2条回答
  •  一向
    一向 (楼主)
    2021-01-17 13:06

    Here's what I've got on the viewDidLoad() or on the button action put the code like this:

    let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Done", otherButtonTitles: "Yes", "No")
              actionSheet.showInView(self.view)
    

    then add another function for their actions like this:

    func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)
        {
            switch buttonIndex{
    
            case 0:
                NSLog("Done");
                break;
            case 1:
                NSLog("Cancel");
                break;
            case 2:
                NSLog("Yes");
                break;
            case 3:
                NSLog("No");
                break;
            default:
                NSLog("Default");
                break;
                //Some code here..
    
            }
    
        }
    

提交回复
热议问题