문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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 ]   
}

`

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top