iOS AlertView触发按下了哪个按钮

时间:2014-06-24 10:44:47

标签: ios uialertview

我正在尝试查看客户端在警报视图按钮上推送了什么选项,尽管日志记录似乎无法正常工作

-(IBAction)flattenBtn:(id)sender
{
    UIAlertView* flatView = [[UIAlertView alloc] initWithTitle:@"Flatten Image"
                                                        message:@"Are you sure you want to flatten your image?" delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"Yes",@"No",nil];
    [flatView show];
    [flatView release];
}


- (void)flatView:(UIAlertView *)flatView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        NSLog(@"YES");
    }
    else if (buttonIndex == 1)
    {
        NSLog(@"NO");
    } 
}

1 个答案:

答案 0 :(得分:1)

尝试使用这样:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Yes"])
    {
       //your code if YES pressed;
    }
    else
    {
      //your code if NO pressed;
    }
}