代码之家  ›  专栏  ›  技术社区  ›  AndyDev

如何确定以前是否加载了UITableViewCell?

  •  4
  • AndyDev  · 技术社区  · 14 年前

    基本上,我想检查UITableView中的一个单元格之前是否已经加载/查看过,以便在单元格的第一个视图上执行动画。有人知道我会怎么做吗?

    我猜这可能是一种倒退的做法,如果你能想出更好的检查方法,那我就洗耳恭听了。

    提前谢谢!

    1 回复  |  直到 14 年前
        1
  •  6
  •   Daniel Dickison    14 年前

    您应该触发动画并跟踪哪些索引路径已经显示在 tableView:willDisplayCell:forRowAtIndexPath:

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // NSMutableSet *animatedIndexPaths; <-- this is an ivar.
        if (![animatedIndexPaths containsObject:indexPath])
        {
            [animatedIndexPaths addObject:indexPath];
            // Trigger your cell animation on cell.
        }
    }