如何创建"otherButtonTitles"?

Dev*_*ted 3 iphone objective-c uialertview

我让AlertView与"cancelButtonTitle:@"取消""和"otherButtonTitles:nil"完美配合.我的问题是如何获得其他按钮.

当我只更改"otherButtonTitles:@"第二个按钮""时,iPhone模拟器刚刚从应用程序崩溃并进入主屏幕.

Kev*_*ner 10

你想结束你的方法调用,如下所示:

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

这与您在String格式中看到的模式相同,其中参数列表可以是任意长度.通常,参数列表以nil结尾.不要忘记零.


Jac*_*kin 6

究竟像凯文说,但作为附录的是,你还可以指定目标行动的其他按钮.

实例化时UIAlertView,将delegate参数设置为self,然后将以下方法添加到对象:

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

`

  • 而且,executor21,它只是一个例子,我知道它可以这样工作,但我的例子是更动态更少的代码. (2认同)