Gre*_*tic 110 iphone uialertview uiactionsheet ios
我有一个字符串数组,我想用于UIActionSheet上的按钮标题.不幸的是,方法调用中的otherButtonTitles:参数采用可变长度的字符串列表,而不是数组.
那我怎么能把这些标题传递到UIActionSheet呢?我见过的解决方法是将nil传递给otherButtonTitles :,然后使用addButtonWithTitle:单独指定按钮标题.但这有将"取消"按钮移动到UIActionSheet上的第一个位置而不是最后一个位置的问题; 我希望它是最后一个.
有没有办法1)传递一个数组代替一个变量的字符串列表,或者2)将取消按钮移动到UIActionSheet的底部?
谢谢.
Jab*_*Jab 248
我得到了这个工作(你只需要,可以使用常规按钮,然后在以下后添加:
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];
Run Code Online (Sandbox Code Playgroud)
Nic*_*ick 78
一个小注意事项:[actionSheet addButtonWithTitle:]返回该按钮的索引,因此为了安全起见并"干净",您可以这样做:
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27474 次 |
| 最近记录: |