开发者

How to create "otherButtonTitles"?

开发者 https://www.devze.com 2022-12-14 22:45 出处:网络
I have the AlertView working p开发者_如何学编程erfectly with a \"cancelButtonTitle:@\"Cancel\"\" and \"otherButtonTitles:nil\". My question is how to get other buttons.

I have the AlertView working p开发者_如何学编程erfectly 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 ]   
}

`

0

精彩评论

暂无评论...
验证码 换一张
取 消