UIAlertView EXC_BAD_ACCESS错误

时间:2012-08-19 03:47:11

标签: objective-c uialertview exc-bad-access uiactionsheet

我无法弄清楚为什么我在操作表方法中的下一行上一直收到EXC_BAD_ACCESS错误:

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:numberFinal]];

我添加了我的代码,但我不明白为什么它被释放了。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    number = [[results objectAtIndex:indexPath.row]objectForKey:@"phone"];

    number = [number stringByReplacingOccurrencesOfString:@"-" withString:@""];
    numberFinal = [NSString stringWithFormat:@"tel:%@",number];
    //tel:1234567890
    NSLog(@"NUMBER:%@",numberFinal);

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UIAlertView *alert2 = [[[UIAlertView alloc]initWithTitle:@"Call" message:@"Call This Person?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil]autorelease];
    alert2.tag = kAlertViewTwo;

    [alert2 show];
   // [alert2 release];


}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    if(actionSheet.tag == kAlertViewOne) {
        if (buttonIndex == 0)
        {
        }else{
        }
    }
    else if(actionSheet.tag == kAlertViewTwo) {
        if (buttonIndex == 0)
        {
            //ok button clicked - close alert  
        }
        else
        {
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:numberFinal]];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

尝试在行之前执行NSLog并打印 numberFinal 以查看它是否已分配好。

确保您的班级是UIAlertView代表

在另一个函数中尝试相同的代码行,看它是否会导致同样的问题。这可能是因为您正在从UIAlertView点击事件中访问sharedApplication。

希望有所帮助:)