Create UIActionSheet 'otherButtons' by passing in array, not varlist

前端 未结 4 811
太阳男子
太阳男子 2020-12-22 22:20

I have an array of strings that I want to use for button titles on a UIActionSheet. Unfortunately, the otherButtonTitles: argument in the method invocation takes a variable

4条回答
  •  别那么骄傲
    2020-12-22 22:52

    I got this to work (you just need to, be ok with a regular button, and just add it after :

    NSArray *array = @[@"1st Button",@"2nd Button",@"3rd Button",@"4th Button"];
    
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
                                                                 delegate:self
                                                        cancelButtonTitle:nil
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:nil];
    
        // ObjC Fast Enumeration
        for (NSString *title in array) {
            [actionSheet addButtonWithTitle:title];
        }
    
        actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
    
        [actionSheet showInView:self.view];
    

提交回复
热议问题