2009-07-29 72 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