Как добавить кнопку к существующему UIActionSheet?

У меня есть этот код:

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
                initWithTitle:@"Illustrations"
                delegate:self
                cancelButtonTitle:@"Cancel"
                destructiveButtonTitle:nil
                otherButtonTitles: @"ABC", @"XYZ",
                nil] autorelease];
UIImage *image = // whatever, snip
if (image != nil)
{
    [actionSheet addButtonWithTitle:@"LMNOP"];
}

и это делает отличную работу по добавлению моей кнопки LMNOP условно.

... ПОСЛЕ кнопки отмены.

Как я могу создать свой лист действия с условной кнопкой? К сожалению, я не могу сделать:

UIActionSheet *actionSheet = [[[UIActionSheet alloc]
      // ... etc.
      otherButtonTitles: someMutableArray
      // ... etc.

потому что это, конечно, помогло бы.

Какие-либо идеи?

Спасибо!

20
задан Olie 11 March 2010 в 02:42
поделиться

1 ответ

Вы можете добавить все кнопки после метода инициализации.

UIActionSheet* sheet = [[[UIActionSheet alloc] init] autorelease];
sheet.title = @"Illustrations";
sheet.delegate = self;
[sheet addButtonWithTitle:@"ABC"];
[sheet addButtonWithTitle:@"XYZ"];
if (condition)
    [sheet addButtonWithTitle:@"LMNOP"];
sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"];
53
ответ дан 29 November 2019 в 23:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: