IOS UITableView reload 刷新某一个cell 或 section

通常刷新整个列表 我们都使用[self.tableView reloadData];

有的时候,有变化更新的只是某一行 row 或者是某个section 所以只更新这一行就好了

//一个section刷新
int section_index=10;//更新第11个sectioin
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section_index] withRowAnimation:UITableViewRowAnimationNone];
//一个cell刷新    
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];  //更新 第一个section的第4行  
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
//一个section刷新 int section_index=10;//更新第11个sectioin [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section_index] withRowAnimation:UITableViewRowAnimationNone]; //一个cell刷新 NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0]; //更新 第一个section的第4行 [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
通常刷新整个列表 我们都使用[self.tableView reloadData]; 有的时候,有变化更新的只是某一行 row 或者是某个section 所以只更新这一行就好了 //一个section刷新 int section_index=10;//更新第11个sectioin [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section_index] withRowAnimation:UITableViewRowAnimationNone]; //一个cell刷新 NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0]; //更新 第一个section的第4行 [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
经验分享 程序员 微信小程序 职场和发展