问题描述
我有一个字符串数组,我想用于UIActionSheet上的按钮标题。不幸的是,方法调用中的otherButtonTitles:参数采用可变长度的字符串列表,而不是数组。
I have an array of strings that I want to use for button titles on a UIActionSheet. Unfortunately, the otherButtonTitles: argument in the method invocation takes a variable length list of strings, not an array.
那么我怎么能将这些标题传递给UIActionSheet?我见过的解决方法是将nil传递给otherButtonTitles :,然后使用addButtonWithTitle:单独指定按钮标题。但这有将取消按钮移动到UIActionSheet上的第一个位置而不是最后一个位置的问题;我希望它是最后一个。
So how I can I pass these titles into the UIActionSheet? The workaround I've seen suggested is to pass nil into otherButtonTitles:, then specify the button titles individually by using addButtonWithTitle:. But this has the problem of moving the "Cancel" button to the first position on the UIActionSheet rather than the last; I want it to be the last one.
有没有办法1)传递一个数组来代替变量的字符串列表,或者2)移动取消UIActionSheet底部的按钮?
Is there a way to 1) pass an array in lieu of a variable list of strings, or alternatively 2) move the cancel button to the bottom of the UIActionSheet?
谢谢。
推荐答案
我得到了这个工作(你只需要,可以使用常规按钮,然后在以下后添加:
I got this to work (you just need to, be ok with a regular button, and just add it after :
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];
这篇关于通过传入数组而不是varlist来创建UIActionSheet的“otherButtons”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!