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