UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:@"szMsg" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"download"];
[alert show];
[alert release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//Code for OK button
}
if (buttonIndex == 1)
{
//Code for download button
}
}
好吧,假设我有 2 个 uialert 并在这两种情况下将委托(delegate)设置为 self,第一个 uialert 包含(确定和下载)按钮,第二个包含(取消和上传)按钮,现在我们需要单独的事件处理程序知道吗?
最佳答案
要在 UIView 中处理多个 UIAlertView,您必须为每个 UIAlertView 设置唯一的标记。
alert.tag = 123;
当从委托(delegate)方法获取响应时,使用唯一的标签管理每个方法。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 123)
{
if (buttonIndex == 0)
{
//Code for OK button
}
else if (buttonIndex == 1)
{
//Code for download button
}
}
else if(alertView.tag == 456)
{
// code to manage another alertview response.
}
}
关于iphone - Objective c 中不同警报的单独事件处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397650/