只刷新cell不刷新section,这问题还难住了一阵子

需要用到:

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

注意:(NSArray *)indexPaths里面的下标要不同的哦,要是往最后插入,要记得看仔细哦

参考:http://blog.csdn.net/likendsl/article/details/17122505

//
//  ViewController.m
//  tableView
//
//  Created by apple on 15/8/6.
//  Copyright (c) 2015年 tqh. All rights reserved.
// #import "ViewController.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> {
    UITableView *tableview;
} @property (nonatomic,strong)NSMutableArray *dataSource; @end @implementation ViewController - (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [[NSMutableArray alloc]initWithArray:@[@"",@"",@""]];
    }
    return _dataSource;
} - (void)viewDidLoad {
    [super viewDidLoad];
    tableview = [[UITableView alloc]initWithFrame:CGRectMake(, ,, )];
    tableview.dataSource = self;
    tableview.delegate = self;
    [tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
    [self.view addSubview:tableview];
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    cell.textLabel.text = @"";
    return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableview beginUpdates];
    NSArray *array1 = [[NSArray alloc]initWithArray:self.dataSource];
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (int i = ; i < array1.count; i ++) {
        NSIndexPath *indexPath_1=[NSIndexPath indexPathForRow:i inSection:];
        [array addObject:indexPath_1];
    }
    array1 = [[NSArray alloc]init];
    [tableview beginUpdates];
    [tableview deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationLeft];
    [tableview endUpdates];
    
    //加载新数据
    self.dataSource = [[NSMutableArray alloc]initWithArray:@[@"",@"",@"",@"",@""]];
    NSArray *array2 = [[NSArray alloc]initWithArray:self.dataSource];
    NSMutableArray *array3 = [[NSMutableArray alloc]init];
    for (int i = ; i < array2.count; i ++) {
        NSIndexPath *indexPath_1=[NSIndexPath indexPathForRow:i inSection:];
        [array3 addObject:indexPath_1];
    }
    array2 = [[NSArray alloc]init];
    [tableview insertRowsAtIndexPaths:array3 withRowAnimation:UITableViewRowAnimationRight];
    [tableview endUpdates];
} @end

数据从3个变成5个了还带动画效果~~~~~~~

UITableView局部刷新的更多相关文章

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

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //1.取消选 ...

  2. UItableview section和cell的局部刷新

    局部刷新//一个section刷新    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    [tableview reloadS ...

  3. iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除

    首先创建项目,在storyboard如下布局控件,设置好约束 然后创建cell模型类XMGWineCell数据模型类XMGWine创建UITableView,设置数据源协议,实现数据源方法懒加载数据这 ...

  4. UITableView的刷新

    UITableView的刷新1> 数据刷新的总体步骤* 修改模型数据* 刷新表格(刷新界面) 2> 刷新表格(刷新界面)的方法* 全局刷新(每一行都会重新刷新)- (void)reload ...

  5. (四十二)tableView的滑动编辑和刷新 -局部刷新和删除刷新 -待解决问题

    tableView的局部刷新有两个方法: 注意这个方法只能用于模型数据的行数不变,否则会出错. [self.tableView reloadRowsAtIndexPaths:<#(NSArray ...

  6. 安卓易学,爬坑不易——腾讯老司机的RecyclerView局部刷新爬坑之路

    针对手游的性能优化,腾讯WeTest平台的Cube工具提供了基本所有相关指标的检测,为手游进行最高效和准确的测试服务,不断改善玩家的体验.目前功能还在免费开放中. 点击地址:http://wetest ...

  7. MVC采用Jquery实现局部刷新

    该文纯粹属于个人学习,有不足之处请多多指教! 效果图: 单击Detail下面出现详细,效果如下: 为了使操作时两个不同的数据源相互干扰,使用局部视图刷新,代码如下: 首先介绍主页Index代码: @m ...

  8. ajax+php+mysql 实现点赞、局部刷新,每个IP只能对一篇文章点赞一次

    主要流程: 点赞—>判断当前设备IP是否对当前文章有过点赞记录—>若有记录,弹出提示“已经赞过了”; 若无记录,当前文章点赞数+1,并在记录设备IP点赞记录的表中插入信息. 文章表 art ...

  9. ASP.Net 在Update Panel局部刷新后 重新绑定JS方法

    我们知道Asp.Net中的Update Panel可以完成页面的局部刷新(实质上是Ajax),但是局部刷新完后,此区域的控件上所绑定的JS方法就会失效,因为我们用如下方法来重新绑定. var prm ...

随机推荐

  1. DIV指令一般用法

    本文最初发表于2015-8-14,是由别的地方迁移过来的 (本文所讲为无符号运算) DIV指令是8086汇编中的除法运算指令,它的结果不是浮点数,而是两个整数:商和余数. 我们来看王爽老师是怎么讲的: ...

  2. ping通IP,telnet 3306不通

    一个同事装的MySQL数据库,无法连接.​​1.查看权限​​2.查看防火墙​​检查用户权限,防火墙都没问题,就是无法连接,能ping通,但是telnet 3306 端口无法成功.​​检查了下数据库配置 ...

  3. VMware共享目录设置

    1.保证虚拟机中已经成功安装了 VMware Tools (非常关键) 2.打开VMware,并使虚拟机处于关机状态,然后请按图中箭头所示进行操作 这样就大功告成了,此时进入虚拟机, 执行命令 cd  ...

  4. DWR在Spring中应用

    这里以传递一个对象为例,来说明dwr在Spring中是怎么配置的. JSP页面: <script src='dwr/interface/instructionOuterService.js'&g ...

  5. C# 获取图片的EXIF 信息

    关于 EXIF 信息的介绍. 1  EXIF,是英文Exchangeable Image File(可交换图像文件)的缩写.EXIF是一种图像文件格式,只是文件的后缀名为jpg.EXIF信息是由数码相 ...

  6. (转)android Fragments详解二:创建Fragment

    创建Fragment 要创建fragment,必须从Fragment或Fragment的派生类派生出一个类.Fragment的代码写起来有些像activity.它具有跟activity一样的回调方法, ...

  7. 与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。

    今天同学请教我数据库为什么打不开了,打开SQL Server 2008 的 SQL Server Management Studio,输入sa的密码发现,无法登陆数据库?提示以下错误: "在 ...

  8. Python实现LR(逻辑回归)

    Python实现LR(逻辑回归) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=>end o ...

  9. VC++编程中获取系统时间

    <span style="white-space:pre"> </span>总结了在程序中如何获得系统时间的方法 void CGetSystenTimeDl ...

  10. (转)Python JSON序列化

    import json # dict to json d=dict(name="cui",age=20,score=88) print json.dumps(d) #list to ...