【发布时间】:2011-10-05 23:53:25
【问题描述】:
我在这里遇到了一个奇怪的问题。我正在开发一个 iOS 应用程序(特别是针对 iPad),并且我在某些时候使用 UITableView 来显示事物列表。
现在,当我在视图边界内滚动时(不在第一个元素之上,也不在最后一个元素之下),它可以正常工作。但是,当我滚动得更远时,它只会剧烈崩溃,除了以下消息之外没有其他消息:
- EXC_BAD_ACCESS 当我向下滚动到最后一个元素时
- SIGABRT 当我滚动到第一个上方时带有回溯
我在 Google 上查看过,似乎我释放了一些对象太多,但我不知道是哪些对象。
我也尝试在 Instruments 中运行该应用程序,但每次我运行该应用程序时 Instruments 窗口都会冻结,迫使我手动将其杀死...当然我没有得到任何结果...
这里有一点相关代码:
/*
Returns the cells of the table view
*/
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create a new cell view
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [newestModules objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"Background-Texture-Dark-Small.png"]];
cell.imageView.image = [UIImage imageNamed:@"Icon-Maths.png"];
UIView *v = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
// Set view background color
v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background-Texture-Dark-Small.png"]];
// This view will be activated when the cell is selected
cell.selectedBackgroundView = v;
return cell;
}
编辑:UITableView 加载和卸载方法:
- (void)viewDidLoad
{
[super viewDidLoad];
// Transparent background
self.tableView.backgroundView = nil;
// Generate list of newest modules. Will later look for them on the internet, but for now we only add some test examples.
newestModules = [[NSMutableArray alloc] initWithObjects:@"Test 1", @"Test 2", @"Test 3", @"Test 4", @"Test 5", nil];
}
- (void)viewDidUnload
{
[newestModules release];
[super viewDidUnload];
}
【问题讨论】:
-
当您注释掉
return cell(这个 selectedNackgroundView 的东西)之前的最后 3 行相关行时,是否仍然出现崩溃? -
即使我注释掉“配置单元格”和“返回单元格”之间的每一行,它实际上也会发生......这就是为什么我有点失落......
-
您的最新模块是如何定义(包括属性)、分配和填充的?
-
我用 viewDidLoad 和 viewDidUnload 方法编辑了我的帖子,因为我在这里分配东西。
-
在获得 EXC_BAD_ACCESS 后您应该尝试的第一件事是运行产品 > 分析 (⇧⌘B) 并设置 NSZombieEnabled。总是这样做。大多数时候它会直接告诉你哪里出错了。
标签: ios uitableview scroll exc-bad-access