我有一个字符串数组,我想将其用于 UIActionSheet 上的按钮标题。不幸的是,方法调用中的 otherButtonTitles: 参数采用可变长度的字符串列表,而不是数组。
那么如何将这些标题传递到 UIActionSheet 中呢?我看到建议的解决方法是将 nil 传递给 otherButtonTitles:,然后使用 addButtonWithTitle: 单独指定按钮标题。但这有将“取消”按钮移动到 UIActionSheet 上的第一个位置而不是最后一个的问题;我希望它是最后一个。
有没有办法 1) 传递一个数组来代替字符串变量列表,或者 2) 将取消按钮移动到 UIActionSheet 的底部?
谢谢。
最佳答案
我让这个工作(你只需要,用一个普通的按钮就可以了,只需在之后添加它:
NSArray *array = @[@"1st Button",@"2nd Button",@"3rd Button",@"4th Button"];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
// ObjC Fast Enumeration
for (NSString *title in array) {
[actionSheet addButtonWithTitle:title];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet showInView:self.view];
关于ios - 通过传入数组而不是 varlist 创建 UIActionSheet 'otherButtons',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2384044/