我确定这一定已经在某个地方得到了回答,但我正在努力寻找答案的正确搜索词。
在我的 objective-c 代码中,我有一个未知数字字符串的 NSArray,我想将其元素传递给可变初始化方法,在这种情况下,它是 UIActionSheet 构造函数中的“otherButtonTitles”列表。如何实现?
提前致谢
最佳答案
我认为您需要将数组的第一个元素传递给构造函数,然后使用 addButtonWithTitle 方法循环遍历其余元素并添加它们:
UIActionSheet *mySheet = [[UIActionSheet alloc] initWithTitle:title delegate:delegate cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:[myOtherButtons objectAtIndex:0],nil];
NSMutableArray *otherbuttons = myOtherButtons;
[otherButtons removeObjectAtIndex:0];
NSEnumerator *enumerator = [otherButtons objectEnumerator];
id anObject;
while (title = [enumerator nextObject]) {
[mySheet addButtonWithTitle:title];
}
关于objective-c - 如何将数组的元素传递给可变参数函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4179118/