这是我正在使用的UIAlertView设置标签,如图所示

 UIAlertView *alertViewDelete = [[UIAlertView alloc] initWithTitle:@"delete User"
                                                                        message:@"can't restore data after deletion"
                                                                       delegate:nil
                                                              cancelButtonTitle:@"delete"
                                                              otherButtonTitles:@"cancel", nil];
                alertViewDelete.tag = 97;
                [alertViewDelete show];


使用此代码读取单击的按钮

- (void)alertView:(UIAlertView *)alertView1 clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(alertView1.tag == 97)
    {
    if(buttonIndex == 1)
    {
        NSLog(@"ok");
    }
        else
        {
            NSLog(@"bye");
        }
    }
}


iOS应用程序目标C ...我要遍历此代码,找不到我在哪里或做错了什么。

最佳答案

你忘了两件事

在您的viewcontroller.h中添加UIAlertviewDelegate



 alertViewDelete.delegate = self;
 alertViewDelete.tag = 97;
 [alertViewDelete show];

07-27 20:20