我的AlertView与“cancelButtonTitle:@”取消“”和“otherButtonTitles:nil”完美配合。我的问题是如何获得其他按钮。如何创建“otherButtonTitles”?
当我只更改“otherButtonTitles:@”2nd Button“”,那么iPhone模拟器刚刚崩溃了应用程序并进入主屏幕。
我的AlertView与“cancelButtonTitle:@”取消“”和“otherButtonTitles:nil”完美配合。我的问题是如何获得其他按钮。如何创建“otherButtonTitles”?
当我只更改“otherButtonTitles:@”2nd Button“”,那么iPhone模拟器刚刚崩溃了应用程序并进入主屏幕。
要结束你的方法调用是这样的:
... cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1Title", @"Button2Title", nil];
这是你看到同样的模式在字符串格式化,其中的参数列表可以是任意长度的。通常参数列表然后以零结尾。不要忘记零。
确切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 ]
}
`
如何控制哪个按钮将激活此方法?我试了一下,无论按哪个按钮(包括取消),它都会运行这个方法。噢噢噢!我在这个方法中设置了一个条件来检查哪个按钮来做什么? – Devoted 2009-12-23 23:58:45
是的。你说对了。 – 2009-12-24 00:12:09
像'[self performSelector:[buttonActions objectAtIndex:buttonIndex]];' 这将工作,如果你有一个名为'buttonActions'的选择器 - 只是一个例子。 – 2009-12-24 00:13:59
不知道关于零。完美的作品,谢谢! – Devoted 2009-12-23 23:55:36