The UIAlertSheet constructor accepts the otherButtonTitles parameter as a varg list. Instead, I would like to specify other button names from NSArray. Is it possible?
i.e. I must do it:
id alert = [[UIActionSheet alloc] initWithTitle: titleString delegate: self cancelButtonTitle: cancelString destructiveButtonTitle: nil otherButtonTitles: button1Title, button2Title, nil];
But since I am generating a list of available buttons at runtime, I really want something like this:
id alert = [[UIActionSheet alloc] initWithTitle: titleString delegate: self cancelButtonTitle: cancelString destructiveButtonTitle: nil otherButtonTitles: otherButtonTitles];
Right now, I think I need to have a separate initWithTitle: call initWithTitle: for 1 item, 2 items and 3 items. Like this:
if ( [titles count] == 1 ) { alert = [[UIActionSheet alloc] initWithTitle: titleString delegate: self cancelButtonTitle: cancelString destructiveButtonTitle: nil otherButtonTitles: [titles objectAtIndex: 0], nil]; } else if ( [titles count] == 2) { alert = [[UIActionSheet alloc] initWithTitle: titleString delegate: self cancelButtonTitle: cancelString destructiveButtonTitle: nil otherButtonTitles: [titles objectAtIndex: 0], [titles objectAtIndex: 1], nil]; } else {
This is a lot of duplicate codes, but it might be wise, since I have no more than three buttons. How can i avoid this?
iphone nsarray uialertsheet
Steven Fisher Oct 21 '09 at 17:10 2009-10-21 17:10
source share