在目标c中为不同的UIAlerts分离事件处理程序

suj*_*jay 2 iphone xcode objective-c

    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
        }
    }
Run Code Online (Sandbox Code Playgroud)

罚款,说我有两个uialerts和委托设置为自我两个案件和第一uialert包含(确定和下载)按钮第二个包含(取消和上传)按钮现在我们需要单独的事件处理程序知道吗?

all*_*Nit 12

要在UIView中处理多个UIAlertView,您必须为每个UIA设置唯一标记.

    alert.tag = 123;
Run Code Online (Sandbox Code Playgroud)

而来自委托方法的响应管理每个都有唯一标记.

    - (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.
       }
    }
Run Code Online (Sandbox Code Playgroud)