美文网首页
UITableview 刷新、删除、增加

UITableview 刷新、删除、增加

作者: 白河三 | 来源:发表于2017-02-24 17:22 被阅读402次

ios UITableview 刷新某一个cell 或 section

一个section刷新

NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];

一个cell刷新

NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];

插入某一行

[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:

UITableViewRowAnimationNone];

插入某一分区

[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];

删除某一行

[self.tableView removeRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:cell.indexPath] withRowAnimation:UITableViewRowAnimationNone];

删除某一分区

[self.tableView removeSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];

刷新某一行

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];

刷新某一分区

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];

更新某一行

[self.tableView updateRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];

更新某一分区

[self.tableView updateSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];

刷新整个tableview

1.处理数据源直接reloaddata 是刷新整个tableview

2.如果不刷新整个tableView 则先删除数据源 然后调相应的方法

如果删除的行时某个分区的最后一行,则相应的也要删除区,删除区时也要对数据源处理返回正确的分数

[self.addArray removeAllObjects];
[self.sectionArr removeObject:@"1分区"];
//            [self.tableView reloadData];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] 
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];

相关文章

网友评论

      本文标题:UITableview 刷新、删除、增加

      本文链接:https://www.haomeiwen.com/subject/wwvwwttx.html