2011-04-27 88 views
0

我想要做的按鈕CLCK以下的事情:「EXC_BAD_ACCESS」我該如何解決這個問題?

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     if (QuestionMutableArray==nil) { 
      [self testIterator]; 
     } 
     else 
     { 
      [myMutableArray release]; 
      [myDictionary release]; 
      [self dismissModalViewControllerAnimated:YES]; 

      //[self release]; 
     } 
    } 
} 

這段代碼可以追溯到parentView控制器......當我再次來此的tableView後,我想重裝我的tableView新的NSMutableArray。如何用dismissModalViewController清空我的集合(NSMutableArray或字典)?

回答

0

不要釋放它使對象nil

1

當您嘗試訪問已釋放的內存時,出現EXC_BAD_ACCESS錯誤。也許你試圖在釋放它們之後訪問數組或字典。相反,請從數組或字典中刪除對象。

+0

- (無效)alertView:(UIAlertView中*)alertView clickedButtonAtIndex:(NSInteger的)buttonIndex { 如果(buttonIndex == 0){ \t \t \t \t [自dismissModalViewControllerAnimated:YES]; \t \t \t \t \t [QuestionMutableArray removeAllObjects]; \t \t \t \t XmlManipulatorObject = [[xmlManipulator alloc] init]; \t \t QuestionMutableArray = [[XmlManipulatorObject ReadXml] retain]; \t \t [self.tableView release]; \t \t \t \t }}我照你說的從Array.But刪除所有對象我不是剛剛從那裏我來到back.What可能是解決讓我List.It的加載新的數據已經試過? – 2011-04-27 19:21:32

0

EXC_BAD_ACCESS通常來自兩方面的原因:

  • 字符串不是開始 '@' 符號和
  • 可憐的內存管理。

在你的情況下,我假設你釋放數組和字典,但是你沒有正確初始化。確保在每次使用之前對它們進行了適當的初始化,並保持保留,直到完成它們。這也可能是由於在界面構建器上玩遊戲引起的:我記得多次連接一個IBOutlet並確定該名稱沒有任何意義,並重命名該屬性。每次連接之後,xcode會自動在dealloc方法中放入一個release語句,如果屬性已經釋放兩次,您可能還想在那裏查看是否在該視圖控制器中使用了IB。