Cancel button in the UIActionSheet below

In UIActionSheet, I have a uitableview and cancel button. By default, the cancel button is displayed at the top. I want it to appear below the table. How to do it?

+5
source share
3 answers

this is work for me:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"SomeTitle" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
[actionSheet addButtonWithTitle:@"Some Action"];        
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons -1;
+6
source

I tried this, and the Cancel button below:

menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet"
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:@"destructive"
                                         otherButtonTitles:@"other1", nil];
menu.actionSheetStyle = UIActionSheetStyleDefault;
[menu addButtonWithTitle:@"Cancel"];

By default, the Cancel button is hidden , adding Cancel will show it.

BUT: if you have additional gui elements in your action sheet, you should

option1) position them to hide other buttons (to have a place for your gui element). Its setup, but may work in some situation OR

option2)

Actionsheet , gui .

: UIPickerView UIActionSheet ( )

0

Example in Swift :

func presentMyActionSheetIOS7() {
    let actionSheet: UIActionSheet = UIActionSheet(title: "What do you want to do?", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil)

    actionSheet.addButtonWithTitle("Change Transparency")
    actionSheet.addButtonWithTitle("Hide Photo")
    actionSheet.addButtonWithTitle("Cancel")
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1

    actionSheet.showInView(self.view)
}

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
    switch buttonIndex {
        case 0:
            println("Change Transparency")
        case 1:
            println("Hide Photo")
        case 2:
            println("Cancel")
        default:
            println("Default")
    }
}
0
source

All Articles