2013-02-12 163 views
-1

以下提示点击数是在一个视图控制器应用程序崩溃时在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

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

如果我们没有点击后退按钮,它会正常工作。问题只出现时在第二视图控制器第一视图控制器警报显示

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

编辑 我明白这个问题。当我点击后退按钮时,我的警报委托释放并委托调用结果错误。我该如何克服这一点?

+1

请张贴堆栈跟踪。 – trojanfoe 2013-02-12 12:20:53

+0

是当前视图 - 控制导航堆栈的第一个视图控制器和做navigationController头这个视图 - 控制 – AppleDelegate 2013-02-12 12:25:45

+0

不,这不是第一个视图控制器 – manujmv 2013-02-12 12:55:05

回答

0

从你在这里描述了该问题可能是这个(猜猜)

[actInd stopAnimating]; 

在之后的viewController称为被移除(弹出)。该actInd可能没有一个有效的内存,因此它崩溃

改变这样的方法内容和检查

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

编码愉快:)

+0

我刚换了一个。但它再次崩溃 – manujmv 2013-02-12 12:37:58

2

我最好的猜测是'self.navigationController'或'actInd'已经发布。此外,你的'UIAlertView'泄漏内存(除非你使用ARC)。使用乐器来分析应用程序,选择“僵尸”工具并查看它出现的内容。

+0

另外,它通常是可取的存储UIAlertViews在保留'@ property',和在上面的代码使用'self.alert = [[UIAlertView中的alloc] ...'。 – mrueg 2013-02-12 14:13:15

0

我相信你必须改变

[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 
} 
+0

对不起。它不工作。警报现在也来。 – manujmv 2013-02-13 04:03:43