16

A UIActionSheet is initalized with:

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

I am trying to pass an NSArray into the "otherButtonTitles" message.

I tried to pass an NSArray using:

otherButtonTitles:[array]

but the message is expecting a list of NSStrings.

The only way I can think of breaking an NSArray into a set of NSStrings is to by using componentsJoinedByString but it gives me a comma separated list that is a single NSString.

A point in the right direction would be appreciated.

2
  • Wow... good question! Maybe using NSInvocation this is possible somehow? Commented Jun 20, 2009 at 3:09
  • I just used the answer from a similar question to do this. It worked very well for me. stackoverflow.com/questions/1602214/… Commented Jan 28, 2011 at 23:49

2 Answers 2

16

That method takes varargs. There's not a really easy way to make the conversion your describing, and it definitely isn't worth the trouble to try in this case. This is just a convenience method.

Just use -init and configure everything with the accessors (-setDelegate:, -addButtonWithTitle:, -setCancelButtonIndex:, etc.)

Sign up to request clarification or add additional context in comments.

1 Comment

See also Brad Smith's answer regarding button ordering when using the "addButtonWithTitle:" approach (but noting that you don't need to subclass the UIActionSheet to use this; they're all public methods): stackoverflow.com/questions/1262205/…
4

Unfortunately, you can't do this in Objective-C.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.