There are many methods in the SDK that ask for a list of strings, terminated by a nil, for example, in UIActionSheet:
- (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
'otherButtonTitles' in this case is a list of NSStrings terminated with a nil. What I'd like to do is call this method with a constructed NSMutableArray of NSStrings, because I'd like to create and order the arguments dynamically. How would I do this? I'm not sure how to create a nil-terminated pointer to NSStrings in this case, and if passing it in would even work. Do I have to alloc the memory for it manually and release it?
You cannot convert any array into a variadic list.
However, for UIActionSheet, you could add those otherButtonTitles after the sheet is created, using -addButtonWithTitle:
UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:...
/*etc*/
otherButtonTitles:nil];
for (NSString* otherButtonTitle in otherButtonTitlesArray)
{
[sheet addButtonWithTitle:otherButtonTitle];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With