2013-02-12 303 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