TableView中删除某个cell或者某个section后重载tableView的问题

通常,我们会遇到这样的问题,tableView中点击了某个cell中的按钮,成功执行这个操作之后对表格进行刷新或者重载,不同的情况,所做的处理也不同,主要分为以下几种:

1.朋友圈点赞:

对于这种情况,点赞成功的回调中这样处理:一般是从模型数组里取出对应行的模型数据,修改该模型的某个属性,并同时将模型数组中的这个对象更新,最后reloadRowsAtIndexPath

[self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];

                


2.侧滑删除:

侧滑按钮点击之后,直接调用tableView的deleteRows方法:

- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

该方法接收一个数组对象作为参数,数组的每个元素必须是NSIndexPath对象,要删除哪些行,就设置NSIndexPath对象的.row属性和.section属性


3.整个section删除:


如图,这个界面的设计思路是每个订单都是一个section,而每个商品都是一个cell(根据需求,一个订单可能有多个商品)

执行"删除订单"或者确认收货之后都需要对tableView进行重新加载操作,这里调用

[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:rightButton.tag -1000] withRowAnimation:UITableViewRowAnimationRight];该方法会移除tableView中的指定section


猜你喜欢

转载自blog.csdn.net/qq_31186665/article/details/52327381