UITableView局部刷新
只刷新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局部刷新的更多相关文章
- 两种局部刷新UITableView的方法的使用条件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //1.取消选 ...
- UItableview section和cell的局部刷新
局部刷新//一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadS ...
- iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除
首先创建项目,在storyboard如下布局控件,设置好约束 然后创建cell模型类XMGWineCell数据模型类XMGWine创建UITableView,设置数据源协议,实现数据源方法懒加载数据这 ...
- UITableView的刷新
UITableView的刷新1> 数据刷新的总体步骤* 修改模型数据* 刷新表格(刷新界面) 2> 刷新表格(刷新界面)的方法* 全局刷新(每一行都会重新刷新)- (void)reload ...
- (四十二)tableView的滑动编辑和刷新 -局部刷新和删除刷新 -待解决问题
tableView的局部刷新有两个方法: 注意这个方法只能用于模型数据的行数不变,否则会出错. [self.tableView reloadRowsAtIndexPaths:<#(NSArray ...
- 安卓易学,爬坑不易——腾讯老司机的RecyclerView局部刷新爬坑之路
针对手游的性能优化,腾讯WeTest平台的Cube工具提供了基本所有相关指标的检测,为手游进行最高效和准确的测试服务,不断改善玩家的体验.目前功能还在免费开放中. 点击地址:http://wetest ...
- MVC采用Jquery实现局部刷新
该文纯粹属于个人学习,有不足之处请多多指教! 效果图: 单击Detail下面出现详细,效果如下: 为了使操作时两个不同的数据源相互干扰,使用局部视图刷新,代码如下: 首先介绍主页Index代码: @m ...
- ajax+php+mysql 实现点赞、局部刷新,每个IP只能对一篇文章点赞一次
主要流程: 点赞—>判断当前设备IP是否对当前文章有过点赞记录—>若有记录,弹出提示“已经赞过了”; 若无记录,当前文章点赞数+1,并在记录设备IP点赞记录的表中插入信息. 文章表 art ...
- ASP.Net 在Update Panel局部刷新后 重新绑定JS方法
我们知道Asp.Net中的Update Panel可以完成页面的局部刷新(实质上是Ajax),但是局部刷新完后,此区域的控件上所绑定的JS方法就会失效,因为我们用如下方法来重新绑定. var prm ...
随机推荐
- windows下找不到strings.h
头文件用的strings.h,换成string.h就好了.但是以前的Linux系统下用strings.h,strerror都能正常编译,怎么样能正常使用strings.h linux系统下的库问题跟w ...
- 转 在SQL Server中创建用户角色及授权(使用SQL语句)
目录 要想成功访问 SQL Server 数据库中的数据 我们需要两个方面的授权 完整的代码示例 使用存储过程来完成用户创建 实例 要想成功访问 SQL Server 数据库中的数据, 我们需要两个 ...
- Xcode真机调试错误之"Please valify your...clock not set"
乍一看错误信息是证书过期,其实是描述证书错乱了. Xcode->Preferences->Account 将选中其中一个描述文件 show in finder,将里面的全都删除.
- Linux rsync 同步
rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用.本文主要讲述的是如何自架rsync服务器,以实现文件传输.备份和镜像.相对tar ...
- [原]Java修炼 之 基础篇(一)Java语言特性
学习软件开发,首先要选择的就是选择需要采用的编程语言,考虑语言本身的优缺点和实际需求,综合评价之后选择相关的语言进行系统开发.本篇博客开始就从近年来比较流行的Java开始为大家讲起. 背景 1995年 ...
- shell操作文件的几条命令:删除最后一列、删除第一行、diff等
删除文件第一行: sed '1d' filename 删除文件最后一列: awk '{print $NF}' filename awk删除重复行的命令:awk '{if (!seen[$0]++) { ...
- UIProgressView swift
// // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...
- document.addEventListener理解
document.addEventListener("事件名称", 函数, false); function 某函数(event){ // 方法执行 } addEventListe ...
- Android -- 浮动组建
在开发Android应用时,加新功能是必不可少的,我们加入了新的功能,有的一看界面就可以看出来,但是有的新功能就比较隐蔽,也就是用户很难知道你添加了这个新功能,这个时候就需要用户在打开我们的应用时给出 ...
- android listview和button,ImageButton等有事件的控件的总结
public ImageButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defSty ...