iphone - Objective c 中不同警报的单独事件处理程序

标签 iphone objective-c xcode

    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/

相关文章:

iphone - 如何使用 AFNetworking 2.0 下载图像?

ios - cocoapods:遇到意外的版本目录。我该如何解决?

iphone - TableView 更新 'NSInternalInconsistencyException',原因 : 'Invalid update: invalid number of rows?

iphone - 当应用程序激活时更新 uilabels

iphone - 我的 HTML5 Canvas 效果可以在 iPhone 或 Android 上运行吗?

iphone - 我怎样才能创建这个数据结构?

ios - CFRelease中的空指针(由静态分析器告知)

iphone - iPhone上的 "X would like to use your current location"背后的规则是什么?

ios - GPUImage 着色器因 "ERROR: One or more attached shaders not successfully compiled"而崩溃

iphone - 如何抽象 Objective C 中的类名或类型以用作变量?