Objective-c - Passing in variables to a variable-length method

后端 未结 2 1828
长发绾君心
长发绾君心 2021-01-19 07:06

I\'ve got an array with items, and I want to pass these in to a variable-length method. How do you do that?

I.e., I\'ve got this (for example):

NSArr         


        
2条回答
  •  旧巷少年郎
    2021-01-19 07:28

    The documentation for the otherButtonTitles parameter in -[UIAlertView initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:] states that:

    Using this argument is equivalent to invoking addButtonWithTitle: with this title to add more buttons.

    Have you tried this:

    NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
    UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
    for (NSString *s in array) {
        [view addButtonWithTitle:s];
    }
    

提交回复
热议问题