TableView- 数据刷新

数据刷新

  • 添加数据
  • 删除数据
  • 更改数据

全局刷新方法(最常用)

[self.tableView reloadData];
// 屏幕上的所有可视的cell都会刷新一遍

局部刷新方法

  • 添加数据
NSArray *indexPaths = @[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]
];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
  • 删除数据
NSArray *indexPaths = @[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]
];
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
  • 更新数据(没有添加和删除数据,仅仅是修改已经存在的数据)
NSArray *indexPaths = @[
[NSIndexPath indexPathForRow:0 inSection:0],
[NSIndexPath indexPathForRow:1 inSection:0]
];
[self.tableView relaodRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];

左滑出现删除按钮

  • 需要实现tableView的代理方法
/**
* 只要实现了这个方法,左滑出现Delete按钮的功能就有了
* 点击了“左滑出现的Delete按钮”会调用这个方法
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// 删除模型
[self.wineArray removeObjectAtIndex:indexPath.row]; // 刷新
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
} /**
* 修改Delete按钮文字为“删除”
*/
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}

左滑出现N个按钮

  • 需要实现tableView的代理方法
/**
* 只要实现了这个方法,左滑出现按钮的功能就有了
(一旦左滑出现了N个按钮,tableView就进入了编辑模式, tableView.editing = YES)
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ } /**
* 左滑cell时出现什么按钮
*/
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"关注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了关注"); // 收回左滑出现的按钮(退出编辑模式)
tableView.editing = NO;
}]; UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self.wineArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}]; return @[action1, action0];
}

进入编辑模式

// self.tabelView.editing = YES;
//加动画
[self.tableView setEditing:YES animated:YES];
// 默认情况下,进入编辑模式时,左边会出现一排红色的“减号”按钮

在编辑模式中多选

// 编辑模式的时候可以多选
self.tableView.allowsMultipleSelectionDuringEditing = YES;
// 进入编辑模式
[self.tableView setEditing:YES animated:YES]; // 获得选中的所有行
self.tableView.indexPathsForSelectedRows;

iOS-UI控件之UITableView(四)- cell数据刷新的更多相关文章

  1. iOS UI控件继承关系图

    闲来无事,把UI控件的继承关系图整理下来,供自己和大家使用.

  2. ios UI控件的简单整理

    把该文件拷贝到.m文件中就能够方便的查找 /** 匿名类目:能够声明方法和变量,属性为private(不同意在外部调用,且不能被继承 */ /** 发送数据的托付方,接收数据的时代理发(即代理的反向传 ...

  3. iOS UI控件总结(全)

    1.UIButton UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake ...

  4. UI控件之UITableView的基本属性

    UITableView:特殊的滚动视图,横向固定,可以在纵向上滚动,自动计算contentSize 创建tableView,初始化时指定样式,默认是plain UITableView *_tableV ...

  5. UI控件之UITableView的协议方法

    <UITableViewDataSource,UITableViewDelegate> //设置表视图的编辑状态 -(void)setEditing:(BOOL)editing anima ...

  6. iOS UI控件

    创建: 2018/04/21 完成: 2018/04/25 更新: 2018/09/24 补充UIActivityIndicatorView的显示和隐藏方法 UIButton  设定项目  项目名   ...

  7. iOS UI控件之间的关系图

  8. IOS学习资源收集--开发UI控件相关

    收集的一些本人了解过的iOS开发UI控件相关的代码资源(本文持续补充更新) 内容大纲: 1.本人在github上也上传了我分装好的一些可重复利用的UI控件 2.计时相关的自定义UILabel控件 正文 ...

  9. iOS基础UI控件介绍-Swift版

    iOS基础UI控件总结 iOS基础控件包括以下几类: 1.继承自NSObject:(暂列为控件) UIColor //颜色 UIImage //图像 2.继承自UIView: 只能相应手势UIGest ...

  10. ios 中的UI控件学习总结(1)

    UIKit框架提供了非常多功能强大又易用的UI控件 下面列举一些在开发中可能用得上的UI控件 UIButton 按钮 UILabel 文本标签 UITextField 文本输入框 UIImageVie ...

随机推荐

  1. 【STORAGE】Qlogic FC存储交换机cmd配置方法

    *************************************************************** ****原文: blog.csdn.net/clark_xu  徐长亮专 ...

  2. VS类添加头文件注释

    VS2015参考: http://blog.csdn.net/qq395537505/article/details/50853546  修改两个文件,详细信息 VS2010: 找到VS的安装目录 E ...

  3. Buildroot 龙芯1C支持指南

    本文转载自:https://github.com/pengphei/smartloong-sphinx/blob/master/source/cn/loongson1c_buildroot_guide ...

  4. bacth参数说明 cmd parameter

    http://www.robvanderwoude.com/parameters.php Windows NT 4 introduced a set of new features for comma ...

  5. RecyclerView的基本用法

    RecyclerView 是一个增强版的ListView,不仅可以实现和ListView同样的效果,还优化了ListView中存在的各种不足之处 ResyslerView 能够实现横向滚动,这是Lis ...

  6. 【Selenium】HTML/XML/XPATH基础

    Html超文本标记语言 网页上单击右键→查看源文件/查看源代码 Html基本结构 <html>               为文档根元素,所有元素都在内部进行 <head>   ...

  7. BZOJ_3209_花神的数论题_组合数+数位DP

    BZOJ_3209_花神的数论题_组合数+数位DP Description 背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 描述 话说花神这天又 ...

  8. 【转】Android 6.0 Marsmallow BLE : Connection Parameters

    原文网址:http://stackoverflow.com/questions/34617061/android-6-0-marsmallow-ble-connection-parameters Th ...

  9. 小程序-文章:微信小程序常见的UI框架/组件库总结

    ylbtech-小程序-文章:微信小程序常见的UI框架/组件库总结 1.返回顶部 1. 想要开发出一套高质量的小程序,运用框架,组件库是省时省力省心必不可少一部分,随着小程序日渐火爆,各种不同类型的小 ...

  10. Windows JDK 1.8降级为1.7方法

    转自:https://www.aliyun.com/jiaocheng/890626.html 正常情况下,JDK的升降级只需更改环境变量即可 可是到了1.8版本,Oracle使了一点小手段, 在系统 ...