我让 AlertView 与“cancelButtonTitle:@"Cancel"”和“otherButtonTitles:nil”完美配合。我的问题是如何获得其他按钮。
当我只更改“otherButtonTitles:@”第二个按钮“”时,iPhone 模拟器就会从应用程序中崩溃并进入主屏幕。
我让 AlertView 与“cancelButtonTitle:@"Cancel"”和“otherButtonTitles:nil”完美配合。我的问题是如何获得其他按钮。
当我只更改“otherButtonTitles:@”第二个按钮“”时,iPhone 模拟器就会从应用程序中崩溃并进入主屏幕。
你想像这样结束你的方法调用:
...cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1Title", @"Button2Title", nil];
这与您在字符串格式中看到的模式相同,其中参数列表可以是任意长度。通常参数列表然后是零终止的。不要忘记零。
就像凯文所说的那样,但作为补充,您还可以将目标操作分配给其他按钮。
当您实例化 时UIAlertView
,将delegate
参数设置为self
,然后将以下方法添加到您的对象:
-(void) alertView: ( UIAlertView *) alertView
clickedButtonAtIndex: ( NSInteger ) buttonIndex {
// do stuff
// if you want the alert to close, just call [ alertView release ]
}
`