Iphone UITableView返回EXC\u错误\u访问
现在加载tableView,但当我尝试向下滚动表格时,应用程序崩溃。这是我的密码:Iphone UITableView返回EXC\u错误\u访问,iphone,cocoa-touch,uitableview,Iphone,Cocoa Touch,Uitableview,现在加载tableView,但当我尝试向下滚动表格时,应用程序崩溃。这是我的密码: - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"ince mal"); NSLog(@"%f", i); UITableViewCell * cell = [tableView dequeueReusable
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"ince mal");
NSLog(@"%f", i);
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
}
// fill it with contents
TFHppleElement * element = [searchResults objectAtIndex:indexPath.row];
NSString * tagContent = [element content];
cell.textLabel.text = tagContent;
return cell;
}
您尚未分配元素,您试图释放它。这就是问题所在 从代码中删除
[element release]
任何保留计数为0的对象都将被释放,然后它将崩溃
设置为检查释放的对象
编辑:
也请删除此行
if (i == indexPath.row) {
return nil;
}
[tagContent release];
如果您想要一个空单元格,则返回为
if (i == indexPath.row) {
return cell; //Before adding any cell contents.
}
永远不要这样做(这会导致另一次崩溃(断言失败)):
至于你的车祸:
[element release];
[tagContent release];
删除这些行我在这些代码中没有看到任何不好的地方。内容物填充线可能会导致一些问题。在你的问题中我甚至找不到任何释放。每当你试图滚动时,CellForRow就会被解雇。因此,检查数组,以访问其对象 您的TableView没有问题,只是您使用它的方式有问题。在您使用它的类中,它被分配、初始化并显示。但我敢打赌,你没有一个指向它的指针来防止它被垃圾收集。你必须接受更多问题的答案。我试过了,这有点帮助。。。现在它加载tableView没有任何问题,但是当我尝试向下滚动表格时,我再次获得了EXC_BAD_访问权限,这就是我所说的(请参见我答案的第一部分)@max:好的,我没有检查你的答案。这里有一些网络故障。那太好了。绝对没问题。我只是想指出另一个问题:我修复了这两个问题并加载了它,但现在当我尝试在tableView中滚动时,应用程序崩溃了,我确信您的代码中仍然有一大堆错误:)
[element release];
[tagContent release];