iOS TableView reaload delete的实际操作

iOS tableview中的 

- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 会创建一个新的cell

- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; 删除一个cell后,其他的cell不会变化,仅会渲染一个新可视的cell

 

不要吧indexpath这个作为cell的一个属性,因为在删除、插入的情况下,只是删除、插入的cell的indexpath会变化,其他的cell如果没有重新赋值都是不变的,这样会有很多不确定的问题。

如果需要获取cell的indexpath,一定要NSIndexPath *reallIndexPath = [self.tableView indexPathForCell:cell];

不要指望table会自动更新或自动reload。

 

猜你喜欢

转载自www.cnblogs.com/programmer-blog/p/12362771.html