【发布时间】:2012-05-29 18:04:28
【问题描述】:
对于我的表格视图,我正在进行以下操作(释义)
.h
@interface OptionsView : UIView <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) NSArray *dataSource;
.m
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
...
self.dataSource = [NSArray arrayWithObjects:options, sections, sponsor, nil];
}
return self;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.dataSource) {
NSArray *ds = [self.dataSource objectAtIndex:indexPath.section];
NSDictionary *d = [ds objectAtIndex:indexPath.row];
ActionBlock a = [d objectForKey:ACTION]; // <-- Thread 1: EXC_BAD_ACCESS (code=2, address=0x802)
if(a != nil) a();
}
}
您可以在我的didSelectRowAtIndexPath 中看到EXC_BAD_ACCESS,但我不知道为什么。因为我使用的是 arc,所以它不是僵尸问题(已经检查过)。
使用断点我看到self.dataSource 在它初始化之后就存在,但在需要它的时候不存在。它也不显示为<nil>,它只是空白。此外,这在调试中有效,但在发布中无效,这是什么意思?
** 编辑添加屏幕截图 **
您会注意到ds 或d 都没有出现.. 奇怪吗?
【问题讨论】:
-
这可能不是一个修复,但对于 ARC,它通常使用弱/强而不是分配/保留属性
-
我不确定它在 xcode 中是否相同,但我也从 Visual Studio 开发中知道,发布版本中的调试符号根本不可靠
-
你能记录下
ds和d的值吗?另一个帮助是将失败的行包装在 @try/@catch 块中并检查异常的描述并调用StackSymbols。 -
如果它在 [d objectForKey:ACTION] 上崩溃;那么“self.dataSource”和“ds”应该仍然存在。
-
@all 截图已添加。这可能会使我的情况更加清晰。
标签: ios uitableview memory-management automatic-ref-counting exc-bad-access