繁体   English   中英

在iOS中单击警报时应用崩溃

[英]app crashes when clicks on alert in ios

以下是在视图控制器中显示警报的代码

-(void)saveProducts {
    pData = [[JsonModel sharedJsonModel] prodData];
    if ([pData count] == 0 && [self respondsToSelector:@selector(alertView:clickedButtonAtIndex:) ]  ) {
        alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"No products against this category" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }


    [self.tblView reloadData];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if (buttonIndex == 0) {
        [self.navigationController popViewControllerAnimated:YES];
        [actInd stopAnimating];
    }

}

但是,在网络速度较慢的情况下,警报会缓慢发出。 如果同时单击导航栏的后退按钮,则弹出导航控制器并在新的视图控制器中显示警报。 但是,当我单击“确定”时,应用程序突然崩溃,并显示EXC_BAD_ACCESS错误。 我也试过

didDismissWithButtonIndex

功能代替

clickedButtonAtIndex

但是发生同样的错误。 请帮我

如果我们不单击后退按钮,它将正常工作。 仅当第一视图控制器警报显示在第二视图控制器中时,才会出现问题

编辑这是错误报告* -[ProductsListing alertView:didDismissWithButtonIndex:]:消息发送到已释放实例0x8478280

编辑我了解这个问题。 当我单击“后退”按钮时,我的警报委托解除分配并委托呼叫结果错误。 我该如何克服?

我最好的猜测是'self.navigationController'或'actInd'已经发布。 另外,“ UIAlertView”会泄漏内存(除非您使用的是ARC)。 使用乐器分析应用程序的轮廓,选择“僵尸”工具,然后查看其附带的内容。

根据您所描述的,这里的问题可能是这样(一个疯狂的猜测)

[actInd stopAnimating];

在viewController移除(弹出)之后调用actInd可能没有有效的内存,因此崩溃

像这样更改方法内容并检查

if (buttonIndex == 0) {
        [actInd stopAnimating];
        [self.navigationController popViewControllerAnimated:YES];
    }

快乐的编码:)

我相信你必须改变

[alert show];

if(self.view.window){
   [alert show];
}

这样,仅当控制器(视图)仍在屏幕上时才显示警报。(为什么要让用户从上一个屏幕中看到警报?)如果您仍然希望显示警报,则...“旧”控制器必须通知“新”用户发生了问题...现在是新控制器的工作来通知用户。

或者您可以尝试更改此部分

    [self.navigationController popViewControllerAnimated:YES];
    [actInd stopAnimating];  

if(self.view.window){
    [self.navigationController popViewControllerAnimated:YES];
    [actInd stopAnimating]; // im not sure where the animation is...so not sure if this shoulb be in here or not
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM