UIActionSheet适用于:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Button1", @"Button2", nil];
Run Code Online (Sandbox Code Playgroud)
我试图将NSArray传递给"otherButtonTitles"消息.
我尝试使用以下方法传递NSArray:
otherButtonTitles:[array]
Run Code Online (Sandbox Code Playgroud)
但消息是期待NSStrings列表.
我能想到将NSArray分解为一组NSStrings的唯一方法是使用componentsJoinedByString,但它给我一个逗号分隔的列表,它是一个NSString.
正确方向的一点将不胜感激.
我有一个行动表,其选项根据具体情况而有所不同.有足够的不同按钮标题,我想首先构建这些按钮标题的数组,但我无法弄清楚如何将其转换为varargs格式.
我想做这样的事情:
NSMutableArray *buttonTitles = [NSMutableArray array];
if (condition1) {
[buttonTitles addObject: @"Do action 1"];
}
if (condition2) {
[buttonTitles addObject: @"Do action 2"];
}
if (condition3) {
[buttonTitles addObject: @"Do action 3"];
}
if (condition4) {
[buttonTitles addObject: @"Do action 4"];
}
UIActionSheet *actionSheet = [[[UIActionSheet alloc] initWithTitle: nil delegate: self cancelButtonTitle: @"Cancel" destructiveButtonTitle: nil otherButtonTitles: buttonTitles] autorelease];
Run Code Online (Sandbox Code Playgroud)
现在显然,如果我必须,我可以做这样的事情:
UIActionSheet *actionSheet = nil;
if (condition1 && condition2 && condition3 && condition4) {
actionSheet = [[[UIActionSheet alloc] initWithTitle: nil delegate: …Run Code Online (Sandbox Code Playgroud) 目前我正在使用
...otherButtonTitles:@"Hotel Laguna", @"Hotel Village", @"Hotel Torre", @"Hotel Baia", nil];
Run Code Online (Sandbox Code Playgroud)
创造一个UIActionSheet.
我想通过一个NSArray ...类似于:
NSArray *names = [[NSArray alloc]
initWithObjects:@"Hotel Laguna", @"Hotel Village", @"Hotel Torre", @"Hotel Baia", nil];
...otherButtonTitles:names];
Run Code Online (Sandbox Code Playgroud)
这有可能吗?
谢谢!