将NSArray分隔为NSString类型对象的列表
-
06-07-2019 - |
题
UIActionSheet被宣布为:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Button1", @"Button2", nil];
我正在尝试将NSArray传递到“otherButtonTitles”中。信息。
我尝试使用以下方式传递NSArray:
otherButtonTitles:[array]
但是消息正在预期NSStrings列表。
我能想到将NSArray分解为一组NSStrings的唯一方法是使用componentsJoinedByString,但它给我一个以逗号分隔的列表,它是一个NSString。
赞赏正确方向的一点。
解决方案
该方法需要varargs。没有一种非常简单的方法可以实现您所描述的转换,在这种情况下尝试转换绝对不值得。这只是一种方便的方法。
只需使用 -init
并使用访问器配置所有内容( -setDelegate:
, -addButtonWithTitle:
, -setCancelButtonIndex:
等。)
其他提示
我刚刚使用类似问题的答案来做到这一点。它对我来说非常好。
不隶属于 StackOverflow