与TableView插入、删除、移动、多选,刷新控件
一、插入、删除、移动、多选
方法一:
Cell的插入、删除、移动都有一个通用的方法,就是更新tableView的数据源,再reloadData,这样做实现上是简单一点,但是reloadData是刷新整个tableView,消耗性能。
方法二:
针对指定的位置进行插入、删除、移动
步骤:
1.让tableView进入编辑状态:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
2.tableView会执行代理返回编辑的种类:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
插入:UITableViewCellEditingStyleInsert,左侧出现红色删除按钮
删除:UITableViewCellEditingStyleDelete,左侧出现绿色添加按钮
移动:UITableViewCellEditingStyleNone,右侧出现灰色移动按钮
多选:UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert,左侧出现圆形选择框
3.在插入、删除、多选的时候右侧的移动按钮也会出现,这是因为tableView的代理- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath默认返回YES,所以默认编辑的时候可以移动,不需要的设置成NO就行了
4.执行tableView实现插入、删除、移动、多选
插入:- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
删除:- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
移动:不需要实现方法,移动后会执行回调- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
多选:不需要什么实现方法,cell的selectionStyle不能为UITableViewCellSelectionStyleNone不然没有多选效果,选中的一个cell的时候会执行代理- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath ,取消选中一个cell的时候执行回调:- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
二、系统刷新控件
在TableViewController中可以使用系统的刷新控件UIRefreshControl
使用方法:
1.创建UIRefreshControl
//初始化
UIRefreshControl *rc = [[UIRefreshControl alloc] init];
//设置Title
rc.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新"];
//响应方法
[rc addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
//赋给TableViewController
self.refreshControl = rc;
- (void)refresh{
//控件状态,是否在刷新状态
if (self.refreshControl.isRefreshing) {
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"加载中"];
}
}
与TableView插入、删除、移动、多选,刷新控件的更多相关文章
- SYRefresh 一款简洁易用的刷新控件 支持tableview,collectionview水平垂直刷新功能
SYRefresh 地址: https://github.com/shushaoyong/SYRefresh 一款简洁易用的刷新控件 示例程序: 默认刷新控件使用方法: //添加头部刷新控件 Sc ...
- iOS:下拉刷新控件UIRefreshControl的详解
下拉刷新控件:UIRefreshControl 1.具体类信息: @interface UIRefreshControl : UIControl //继承控制类 - (instancetype)ini ...
- # iOS 10 适配 # 适配刷新控件 以MJRefresh 为例
在iOS10中ScrollView 添加了一个refreshControl的东西 - - 不知道水果公司做了什么 导致原有的刷新控件类刷新后frame.y 向下偏移了20 起初以为是水果调整了sta ...
- 上拉加载下拉刷新控件WaterRefreshLoadMoreView
上拉加载下拉刷新控件WaterRefreshLoadMoreView 效果: 源码: // // SRSlimeView // @author SR // Modified by JunHan on ...
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
本文转载至 http://www.cocoachina.com/ios/20141110/10177.html iOS开发自定义刷新CBStoreHouseRefres 介绍 这是一款在Storeho ...
- [Swift通天遁地]二、表格表单-(4)使用系统自带的下拉刷新控件,制作表格的下拉刷新效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Android 解决下拉刷新控件和ScrollVIew的滑动冲突问题。
最近项目要实现ScrollView中嵌套广告轮播图+RecyleView卡片布局,并且RecyleView按照header和内容的排列样式,因为RecyleView的可扩展性很强,所以我毫无疑问的选择 ...
- ios--->上下拉刷新控件MJRefresh
上下拉刷新控件MJRefresh 一.类结构 MJRefreshComponent.h MJRefreshHeader.h MJRefreshFooter.h MJRefreshAutoFooter. ...
- android官方下拉刷新控件SwipeRefreshLayout的使用
可能开发安卓的人大多数都用过很多下拉刷新的开源组件,但是今天用了官方v4支持包的SwipeRefreshLayout觉得效果也蛮不错的,特拿出来分享. 简介:SwipeRefreshLayout组件只 ...
随机推荐
- OpenJudge 2985数字组合 解析报告/DP
2985:数字组合 总时间限制: 1000ms 内存限制: 65536kB 描述 有n个正整数,找出其中和为t(t也是正整数)的可能的组合方式.如:n=5,5个数分别为1,2,3,4,5,t=5: ...
- 解决MVC EF Code First错误:Model compatibility cannot be checked because the EdmMetadata type was not included in the model.
Model compatibility cannot be checked because the EdmMetadata type was not included in the model. En ...
- struct
struct QSortStack { public int high; public int low; } QSortStack* stack = ]; unsafe static void qso ...
- MongoDB在实际项目中的使用
MongoDB简介 MongoDB是近些年来流行起来的NoSql的代表,和传统数据库最大的区别是支持文档型数据库. 当然,现在的一些数据库通过自定义复合类型,可变长数组等手段也可以模拟文档型数据库. ...
- jquery基本选择器匹配多个元素
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- mysql中,ENCODE警告---Warning Code : 1287
mysql中,ENCODE警告 共 1 行受到影响, 1 个警告 执行耗时 : 0.072 sec传送时间 : 0.001 sec总耗时 : 0.073 sec Warning Code : 1287 ...
- POJ 1811 大素数判断
数据范围很大,用米勒罗宾测试和Pollard_Rho法可以分解大数. 模板在代码中 O.O #include <iostream> #include <cstdio> #inc ...
- 参数化命令相关知识点之==================防止SQl的注入
一: 使用参数化命令查询DAL类: public DataTable StudentDAL(string name,string gender) { string str="连接字符串&qu ...
- C#操作Excel的函数
对于Excel的数据处理功能,大家都已经了解. 我们经常需要将数据导入到Excel,或直接打开Excel文档,读写文件操作,这需要用到ExcelHelper类,有了这个类,这些操作大大的减少我们工作量 ...
- javascript适合移动端的响应式瀑布流插件实例演示
在线预览 jQuery插件大全 实例代码 <div class="sucaihuo-container"> <div class="demo" ...