I have this code:
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"];
}
and it does a great job of adding my LMNOP button conditionally.
...AFTER the cancel button.
How can I construct my action sheet with a conditional button? Sadly, I can't do:
UIActionSheet *actionSheet = [[[UIActionSheet alloc]
// ... etc.
otherButtonTitles: someMutableArray
// ... etc.
because that would certainly help.
Any ideas?
Thanks!
You can add all buttons after the init method.
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"];