Listing NSS Downstream Strings as NSString *

There are many methods in the SDK that request a list of strings ending in zero, for example, in a UIActionSheet file:

- (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 by zero. What I would like to do is call this method with the built NSMutableArray from NSStrings, because I would like to dynamically create and organize the arguments. How should I do it? I am not sure how to create an NSS pointer for NLS in this case, and if its transfer will work. Do I have to allocate memory for her manually and release it?

+5
source share
3 answers

You cannot convert any array to a variable list.

, UIActionSheet ButtonTitles , -addButtonWithTitle:

UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:...
                                                        /*etc*/
                                          otherButtonTitles:nil];
for (NSString* otherButtonTitle in otherButtonTitlesArray)
{
   [sheet addButtonWithTitle:otherButtonTitle];
}
+9

. . . ​​ "" .

sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:homeName, nil];    
[sheet addButtonWithTitle:otherButton1];
[sheet addButtonWithTitle:otherButton2];
[sheet addButtonWithTitle:@"Cancel"];
[sheet setCancelButtonIndex:[sheet numberOfButtons] - 1];
sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[sheet showInView:self.view];
[sheet release];
+5

Are you sure CAN convert NSArray to va_list. For example, for use withNSString

- (id)initWithFormat:(NSString *)format arguments:(va_list)argList

Like this:

+ (id)stringWithFormat:(NSString *)format array:(NSArray *)arguments;
{
    NSRange range = NSMakeRange(0, [arguments count]);
    NSMutableData *data = [NSMutableData dataWithLength:sizeof(id) * [arguments count]];
    [arguments getObjects:(__unsafe_unretained id *) data.mutableBytes range:range];
    return [[NSString alloc] initWithFormat:format arguments:data.mutableBytes];
}
+1
source

All Articles