【问题标题】:Separate NSArray to a list of NSString type objects将 NSArray 分离为 NSString 类型对象的列表
【发布时间】:2010-11-04 11:35:54
【问题描述】:

一个 UIActionSheet 被初始化为:

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

我正在尝试将 NSArray 传递给“otherButtonTitles”消息。

我尝试使用以下方法传递一个 NSArray:

otherButtonTitles:[array]

但消息需要一个 NSString 列表。

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

我们将不胜感激。

【问题讨论】:

  • 哇...好问题!也许使用 NSInvocation 可以通过某种方式实现?
  • 我只是使用了类似问题的答案来做到这一点。它对我来说效果很好。 stackoverflow.com/questions/1602214/…

标签: iphone objective-c nsstring nsarray variadic-functions


【解决方案1】:

该方法采用可变参数。没有一种非常简单的方法可以使转换成为您的描述,在这种情况下绝对不值得尝试。这只是一种方便的方法。

只需使用 -init 并使用访问器配置所有内容(-setDelegate:-addButtonWithTitle:-setCancelButtonIndex: 等)

【讨论】:

  • 另见 Brad Smith 对使用“addButtonWithTitle:”方法时按钮排序的回答(但请注意,您 不需要 需要子类化 UIActionSheet 才能使用它;他们'重新所有公共方法):stackoverflow.com/questions/1262205/…
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多