In UIActionSheet i have a uitableview and cancel button. By default cancel button appears at the top. I want to make it appear at the bottom after tableview. How do i do that?
Asked
Active
Viewed 3,851 times
3 Answers
6
it 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;

Kyle Clegg
- 38,547
- 26
- 130
- 141

Alexander Merchi
- 1,495
- 13
- 11
-
1You are right on. If you use `addButtonWithTitle:` rather than taking care of all of it with the initializer then you'll need to specify the index of the cancel button. – Kyle Clegg Aug 20 '14 at 21:21
0
I tried this and Cancel button is at the bottom:
menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"destructive"
otherButtonTitles:@"other1", nil];
menu.actionSheetStyle = UIActionSheetStyleDefault;
[menu addButtonWithTitle:@"Cancel"];
By default Cancel button is hidden, adding a Cancel will shows it.
BUT: if you have additional gui elements on your actionsheet you have to
option1) position those to hide other buttons (to have space for your gui element). Its a tweak, but can work in some situation OR
option2) you have to manually add your button to the actionsheet
Actionsheet's built-in buttons are not align-able to the bottom freely because the purpose is different for this built-in gui elements.
See this: Adding UIPickerView to UIActionSheet (buttons at the bottom)
-
this works because u have couple of other buttons above cancel button. But in my case i dont have any other button. its just a tableview and cancel button – Arun Apr 22 '13 at 06:56
-
Finally I understand your set-up, so I think only option for you is to add a UIButton to your ActionSheet. – nzs Apr 22 '13 at 06:59
-
What u might to make sure (for me it was a problem) to place your uibutton on the uiactionsheet canvas (frame). Without this uibutton presses will not dispatch properly. This can arise if uiactionsheet's frame is not as big as all elements can be placed correctly on it. – nzs Apr 22 '13 at 07:05
-
For custom adding UIBUtton see my SO link in this post... and if it is works for you you may accept my answer ;) – nzs Apr 22 '13 at 07:20
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")
}
}

King-Wizard
- 15,628
- 6
- 82
- 76