2009-06-20 63 views
16

甲UIActionSheet被initalized用:独立的NSArray到的NSString类型对象的列表

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil 
otherButtonTitles:@"Button1", @"Button2", nil]; 

我试图一个NSArray传递到“otherButtonTitles”消息。

我试着使用通过一个NSArray:

otherButtonTitles:[array] 

但该消息期待NSString的列表。

我能想到的将NSArray分解为一组NSStrings的唯一方法是使用componentsJoinedByString,但它给了我一个逗号分隔的列表,它是一个NSString。

一个正确的方向点将不胜感激。

+0

哇......好问题!也许使用NSInvocation这可能以某种方式? – 2009-06-20 03:09:35

回答

16

该方法需要可变参数。用你的描述进行转换并不是一个简单的方法,在这种情况下尝试这种转换绝对不值得。这只是一个方便的方法。

只需使用-init并配置

+0

另请参阅Brad Smith在使用“addButtonWithTitle:”方法时按钮排序的回答(但注意您*不要*需要继承UIActionSheet以使用它;它们都是公共方法):http://stackoverflow.com/questions/1262205/uiactionsheet-addbuttonwithtitle-doesnt-add-buttons-in-the-right-order – 2011-12-15 13:58:18

4

不幸的是,you can't do this在Objective-C中。

+0

请参阅http://www.cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html – 2014-01-30 00:54:37

相关问题