在UIActionSheet中,我有一个UITableView和取消按钮。默认情况下,取消按钮出现在顶部。我想把它放在表格视图之后的底部。我该怎么做?
在UIActionSheet中,我有一个UITableView和取消按钮。默认情况下,取消按钮出现在顶部。我想把它放在表格视图之后的底部。我该怎么做?
对我来说这很有效:
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;
在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")
}
}
我尝试过这个,取消按钮在底部:
menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"destructive"
otherButtonTitles:@"other1", nil];
menu.actionSheetStyle = UIActionSheetStyleDefault;
[menu addButtonWithTitle:@"Cancel"];
默认情况下,取消按钮是隐藏的,添加取消将显示它。
但是:如果您在操作表上有其他GUI元素,则必须
选项1)将它们定位以隐藏其他按钮(为您的GUI元素腾出空间)。这是一个调整,但在某些情况下可以起作用。或者
选项2)您必须手动将按钮添加到操作表中。
操作表的内置按钮不能自由地对齐到底部,因为此内置GUI元素的目的不同。
addButtonWithTitle:
而不是使用初始化程序来处理所有内容,那么你需要指定取消按钮的索引。 - Kyle Clegg