cellForRowAtIndexPath随机调用,似乎泄漏内存

时间:2014-09-16 18:08:43

标签: ios objective-c uitableview

在我的应用中,我有以下cellForRowAtIndexPath方法。根据我的理解,只应调用此方法来显示当前能够在屏幕上显示的单元格。可以看出,我有一个NSLog()函数,应显示tableView应显示的行。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%ld",(long)indexPath.row);
    PFObject *obj = [vars.feed objectAtIndex:indexPath.row];
    if([obj.parseClassName isEqualToString:@"ProductCategory"]) {
        CategoryTableCell *categoryCell = [tableView dequeueReusableCellWithIdentifier:categoryCellId forIndexPath:indexPath];

        ProductCategory *category = (ProductCategory*)obj;
        [categoryCell.nameLabel setText:category.name];
        [categoryCell.numItemsLabel setText:[NSString stringWithFormat:@"%d Items",[functions numberOfItemsInCategory:category]]];
        [categoryCell.banner setImage:[UIImage imageWithData:category.banner.getData]];

        return categoryCell;
    } else {
        ProductVerticalTableCell *productCell = [tableView dequeueReusableCellWithIdentifier:productCellId forIndexPath:indexPath];
        [productCell customInit];

        ProductPrice *pp = (ProductPrice*)obj;
        productCell.pp = pp;
        productCell.banner.image = [UIImage imageWithData:pp.product.banner.getData];

        return productCell;
    }
}

单元格高度为175,在iPhone 5上一次只能显示3个。预期的结果应为:

2014-09-16 13:55:06.331 Runn[38296:60b] 0
2014-09-16 13:55:06.333 Runn[38296:60b] 1
2014-09-16 13:55:06.335 Runn[38296:60b] 2

事实上,这是日志中唯一出现一秒的东西,但突然间它会遍历所有行并注销:

2014-09-16 13:55:06.331 Runn[38296:60b] 0
2014-09-16 13:55:06.333 Runn[38296:60b] 1
2014-09-16 13:55:06.335 Runn[38296:60b] 2
2014-09-16 13:55:08.389 Runn[38296:60b] 3
2014-09-16 13:55:08.393 Runn[38296:60b] 4
2014-09-16 13:55:08.395 Runn[38296:60b] 5
2014-09-16 13:55:08.396 Runn[38296:60b] 6
2014-09-16 13:55:08.397 Runn[38296:60b] 7
2014-09-16 13:55:08.399 Runn[38296:60b] 8
2014-09-16 13:55:08.400 Runn[38296:60b] 9
2014-09-16 13:55:08.401 Runn[38296:60b] 10
2014-09-16 13:55:08.402 Runn[38296:60b] 11

然后当我滚动,直接向下到底部,完全没有后退,完整的日志看起来像这样:

2014-09-16 13:55:06.331 Runn[38296:60b] 0
2014-09-16 13:55:06.333 Runn[38296:60b] 1
2014-09-16 13:55:06.335 Runn[38296:60b] 2
2014-09-16 13:55:08.389 Runn[38296:60b] 3
2014-09-16 13:55:08.393 Runn[38296:60b] 4
2014-09-16 13:55:08.395 Runn[38296:60b] 5
2014-09-16 13:55:08.396 Runn[38296:60b] 6
2014-09-16 13:55:08.397 Runn[38296:60b] 7
2014-09-16 13:55:08.399 Runn[38296:60b] 8
2014-09-16 13:55:08.400 Runn[38296:60b] 9
2014-09-16 13:55:08.401 Runn[38296:60b] 10
2014-09-16 13:55:08.402 Runn[38296:60b] 11
2014-09-16 13:55:13.428 Runn[38296:60b] 3
2014-09-16 13:55:13.671 Runn[38296:60b] 4
2014-09-16 13:55:13.905 Runn[38296:60b] 5
2014-09-16 13:55:14.338 Runn[38296:60b] 6
2014-09-16 13:55:16.494 Runn[38296:60b] 1
2014-09-16 13:55:16.496 Runn[38296:60b] 2
2014-09-16 13:55:21.856 Runn[38296:60b] 7
2014-09-16 13:55:22.056 Runn[38296:60b] 8
2014-09-16 13:55:22.340 Runn[38296:60b] 9
2014-09-16 13:55:23.039 Runn[38296:60b] 10
2014-09-16 13:55:24.551 Runn[38296:60b] 4
2014-09-16 13:55:24.553 Runn[38296:60b] 5
2014-09-16 13:55:24.554 Runn[38296:60b] 6

0 个答案:

没有答案