Question

I have the AlertView working perfectly with a "cancelButtonTitle:@"Cancel"" and "otherButtonTitles:nil". My question is how to get other buttons.

When I only change the "otherButtonTitles:@"2nd Button"", then the iPhone simulator just crashes out of the app and into the homescreen.

Was it helpful?

Solution

You want to end your method call like this:

... cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1Title", @"Button2Title", nil];

This is the same pattern you see in String formatting, where the list of arguments can be of any length. Usually the argument list is then nil-terminated. Don't forget the nil.

OTHER TIPS

Exactly like Kevin said, but as an addendum to that, you can also assign target-actions to the other buttons.

When you instantiate the UIAlertView, set the delegate argument to self, then add the following method to your object:

-(void) alertView: ( UIAlertView *) alertView 
         clickedButtonAtIndex: ( NSInteger ) buttonIndex {
      // do stuff
      // if you want the alert to close, just call [ alertView release ]   
}

`

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top