【问题标题】:when i set delegate.self in uialertview application is crash in arc当我在 uialertview 应用程序中设置 delegate.self 在 arc 中崩溃时
【发布时间】:2013-12-30 07:22:17
【问题描述】:
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");

    }
}

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

【问题讨论】:

    标签: ios objective-c uialertview uialertviewdelegate


    【解决方案1】:

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

    在这种情况下,您需要检查是否 UIAlertview 的委托在呈现后已被释放,因此当警报被解除时,它不会向其委托发送消息,这可能是 nil。另一种选择是呈现警报视图的 UIViewController 在呈现后被释放。请检查警报代表在呈现后是否未释放。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 2016-08-22
      相关资源
      最近更新 更多