两种局部刷新UITableView的方法的使用条件

 1 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 2 
 3   //1.取消选中这一行
 4 
 5   [tableView deselectRowAtIndexPath:indexPath animated:YES];
 6 
 7   //2.获取当前选中的数据
 8 
 9   Shop *shop = _shops[indexPath.row];
10 
11   //3.控制当前cell是否被选中
12 
13   if( [_deleteShops containsObject:shop] ){
14 
15     //如果之前已选中,现在取消选中
16 
17     [_deleteShops removeObject:shop];
18 
19   }else{
20 
21     //如果之前已取消选中,则现在选中
22 
23     [_deleteShops addObject:shop];
24 
25   }
26 
27   //4.刷新表格(1.此局部刷新方法的使用条件:在tableView总数量不变的情况下,才能用它进行局部刷新)
28 
29   [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
30 
31   //(2.此局部刷新方法的使用条件:调用此方法删除多少行数据,tableView也要删除相同数量的数据)
32 
33   [tableView deleteRowsAtIndexPaths:[indexPath] withRowAnimation:UITableViewRowAnimationTop];
34 
35 }
原文地址:https://www.cnblogs.com/hw140430/p/3703020.html