Подтвердить что ты не робот

Как добавить кнопку в существующую таблицу 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.

потому что это, безусловно, поможет.

Любые идеи?

Спасибо!

4b9b3361

Ответ 1

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

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"];

Ответ 2

im кодирование для iOS 4, и это метод, который используется. Вы просто добавляете заголовок, который хотите использовать для кнопки в других разделах.

UIActionSheet *phoneActionSheet = [[UIActionSheet alloc]
                                          initWithTitle:@"Do you want to call or text this person?"
                                          delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          destructiveButtonTitle:@"Call"                                            
                                          otherButtonTitles:@"Text",nil];