UIActionSheet with swift

后端 未结 5 1349
清酒与你
清酒与你 2021-02-20 15:07

I created an action sheet, but the problem is that the delegate method is not called

 myActionSheet = UIActionSheet()
        myActionSheet.addButtonWithTitle(\"         


        
5条回答
  •  太阳男子
    2021-02-20 15:32

    UIActionSheet in swift language :-

    Action Sheet with cancelButton and destructiveButton

    set the UIActionSheetDelegate.

            let actionSheet = UIActionSheet(title: "ActionSheet", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Done")
            actionSheet.showInView(self.view)
    

    Action Sheet with cancelButton , destructiveButton and otherButton

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

    create the Action sheet function

    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..
    
     }
    

提交回复
热议问题