Elr*_*ric 5 objective-c variadic-functions nsarray
我敢肯定这已经在某个地方得到了解答,但我很难找到合适的搜索条件来解答答案.
在我的objective-c代码中,我有一个未知数字字符串的NSArray,我希望将其元素传递给可变参数的init方法,在这种情况下,它是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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
802 次 |
| 最近记录: |