2009-07-29 70 views
0

這裏選擇的代碼崩潰是代碼:http://pastie.org/562956目標C - 在導航控制器

在電話會議上itemsArray.count「didSelectRowAtIndexPath方法」這個代碼崩潰。我不明白爲什麼... itemsArray是訪問其他方法,如「numberOfRowsInSection」。爲什麼它會突然被取消引用(我認爲這是發生了什麼)。

這裏是輸出(不知道這是怎麼回事用「無法讀取未知加載命令爲0x22」要麼)

[會話開始於2009-07-28二十二時十一分50秒-0600] 警告 - 無找到「NSUserDefaults-Optimize.m:81」的地點 GNU gdb 6.3.50-20050815(Apple版本gdb-966)(Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software Foundation,Inc. GDB是GNU通用公共許可證涵蓋的免費軟件,歡迎您在特定條件下對其進行更改和/或分發。 輸入「show copying」查看條件。 GDB絕對沒有保修。請輸入「顯示保修」以瞭解詳情。 這GDB被配置爲「I386的蘋果達爾文」 .sharedlibrary應用負載規則所有附加 處理56173. 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知加載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知的加載命令0x22 無法讀取未知的加載命令0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知負載命令爲0x22 無法讀取未知的加載命令0x22 無法讀取未知的加載命令0x22 Send2iPhone [56173:20b]加載項目 2009-07-28 22:11:55.629 Send2iPhone [56173:20b] cellforrow 0 2009-07-28 22:11:55.634 Send2iPhone [56173:20b] value =(null) 2009-07-28 22:11:55.644 Send2iPhone [56173:20b] cellforrow 1 2009-07-28 22 :11:55.645 Send2iPhone [56173 :20b] value =(null) 2009-07-28 22:11:55.654 Send2iPhone [56173:20b] cellforrow 2 2009-07-28 22:11:55.658 Send2iPhone [56173:20b] value =(null) 2009-07-28 22:11:55.659 Send2iPhone [56173:20b] cellforrow 3 2009-07-28 22:11:55.663 Send2iPhone [56173:20b] value =(null) 2009-07-28 22:11: 57.724 Send2iPhone [56173:20b] row = 0 節目接收信號:「EXC_BAD_ACCESS」。 殺 退出

調試器已退出,狀態0(GDB)

回答

2

查克有正確的,你沒有保留陣列。

一個解決方法是使itemsArray所述控制器的屬性,以便在頭

@interface RootViewController : UITableViewController { 
    NSArray *itemsArray; 
    NSString *test; 

} 

//add the property directive for itemsArray and tell it to use retain 
@property (nonatomic, retain) NSArray *itemsArray; 

並在.M

@implementation RootViewController 
// add the synthesize for itemsArray property 
@synthesize itemsArray; 


// when you set the value of itemsArray use self.itemsArray this will properly retain the array 
self.itemsArray = [NSArray arrayWithContentsOfURL:plistURL]; 


// release the itemsArray in dealloc 
- (void)dealloc { 
    [itemsArray release]; 
    [super dealloc]; 
} 
2

你不是自稱itemsArray的所有權,所以它是由在某些時候自動釋放池釋放。您可以通過使用正確保留和釋放的訪問器設置變量來解決此問題。另外,如果你還沒有,你應該閱讀Cocoa memory management guidelines