开发者

How to create "otherButtonTitles"?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜