首页 > 其他 > 详细

更新、插入tableview某一行数据或section数据

时间:2015-07-30 21:29:23      阅读:444      评论:0      收藏:0      [点我收藏+]

一、刷新列表

当tableview的某一行数据修改后,需要更新该条数据。这时有两种方法刷新:

(1)刷新整个列表 ,即[self.tableView reloadData]; 

(2)只刷新被改变的这一行。当然这种方法比第一种方法更高效。

具体代码:

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

    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:refreshCell, nil] withRowAnimation:UITableViewRowAnimationNone];

 

        二、插入一行数据数据

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

  NSArray *insertIndexPaths = [NSArray arrayWithObjects:refreshCell,nil];

    //同样,将数据加到数据列表中

      [_meterModelArray insertObject:device atIndex:i+1];

    [self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationRight];

三、刷新某个Section的数据

  NSIndexSet *refreshSection=[[NSIndexSet alloc]initWithIndex:1];//刷新第二个section

    [self.tableView reloadSections:refreshSection withRowAnimation:UITableViewRowAnimationAutomatic];

      四、插入一个section数据

根据上面的一样,改一下就可以,就不再写了。


   

版权声明:本文为博主原创文章,未经博主允许不得转载。

更新、插入tableview某一行数据或section数据

原文:http://blog.csdn.net/lijuan3203/article/details/47152579

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!