当我在uialertview中设置delegate.self时应用程序崩溃了

时间:2013-12-30 07:22:18

标签: ios objective-c uialertview uialertviewdelegate

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Order"
                                                    message:@"Order Successfully Discontinued."
                                                   delegate:self
                                                 cancelButtonTitle:nil
                                          otherButtonTitles: @"Ok",nil];
//[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
alertView.tag=TAG_DEV;

[alertView show];



-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{


    if(alertView.tag==TAG_DEV)
    {
        if(buttonIndex==0)
        {

        }
        else
            NSLog(@"Here");

    }
}

这次崩溃。我该如何解决?

1 个答案:

答案 0 :(得分:0)

当您在“objc_msgSend()”崩溃时,您很可能会向已经释放的对象发送消息。或者你有一个指针,这是正确的,但有些东西改变了对象的内容。另一个原因可能是使用悬挂指针,该指针曾指向现在由对象占用的内存。偶尔objc_msgSend崩溃是因为内存错误改变了运行时自己的数据结构,这会在接收者对象本身造成麻烦。

在这种情况下你需要检查一下,UIAlertview的代表在提交后已被释放,所以当警报被解除时,它不会向它的代表发送消息,这可能是零。另一个选项是呈现警报视图的UIViewController在呈现后被释放。请检查警报代表在出现后是否未发布。