看到Metro大都会 这个App中扣款顺序有个cell可以移动,于是觉得是时候回忆一下UITableView的基本使用了。其实他这个移动cell的功能是系统自带的。

代码主要是这样:

//
// ViewController.m
// UITableViewCell移动Demo
//
// Created by LiuWei on 2018/3/12.
// Copyright © 2018年 xxx. All rights reserved.
// #import "ViewController.h" @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
[self.view addSubview:_tableView];
_tableView.delegate = self;
_tableView.dataSource = self;
//允许编辑
[_tableView setEditing:YES];
} #pragma Mark -- UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ;
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.textLabel.text = [NSString stringWithFormat:@"我是第%lu个cell",indexPath.row];
return cell;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ;
} //默认编辑模式下,每个cell左边有个红色的删除按钮,设置为None即可去掉
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
//是否允许indexPath的cell移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//实现该方法 cell右侧出现3条横线
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
//NSIndexPath 有section和row属性可调用 能找到数据源
NSLog(@"s = %@ -- d = %@",sourceIndexPath,destinationIndexPath); } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

如果要自定义移动效果,参考他的做法:https://www.jianshu.com/p/ce382f9bc794

UITableViewCell的移动的更多相关文章

  1. UITableViewCell定制

    UITableViewCell定制 效果       特点 1.可以添加不同的TableViewCell,可以定制不同的cell样式; 2.可以动态改变cell的高度; 3.可以随意摆放你cell的位 ...

  2. 自定义UITableViewCell实现左滑动多菜单功能LeftSwipe

    今天愚人节,小伙们,愚人节快乐! 实现一个小功能,滑动菜单,显示隐藏的功能菜单, 先上图:                       这里尝试用了下使用三个方式来实现了这个功能: 1.使用自定义UI ...

  3. 【ios开发】UITableViewCell的重用

    移动开发需要解决的一个问题就是资源稀缺的问题.多数情况下是内存问题. 虽然现在的手机都号称大内存,高配置.但是移动app所占用的资源也在跟着不断膨胀, 也是造成内存不足的主要原因. 在前面的例子中,还 ...

  4. UITableViewCell 的附件类型 accessoryType 选中、详情、箭头

    UITableViewCell * cell = [[UITableViewCell alloc] init]; 设置cell的附件类型: // >1 打钩 选中//    cell.acces ...

  5. 【转】自定义UITableViewCell(registerNib: 与 registerClass: 的区别)

    自定义UITableViewCell大致有两类方法: 使用nib 1.xib中指定cell的Class为自定义cell类型(注意不是设置File's Owner的class) 2.调用 tableVi ...

  6. 动态计算UITableViewCell高度

    动态计算UITableViewCell高度 UILabel in UITableViewCell Auto Layout - UILabel的属性Lines设为了0表示显示多行.Auto Layout ...

  7. 【Swift】UITableViewCell 中 TTTAttributedLabel 超链接无法点击的问题

    前言 还以为是自己代码写的有问题,用法和别的地方都一样,但是这个是在 UITableViewCell 中使用,另外在 tableHeaderView 中使用也没用这个问题 —— 使用 TTTAttri ...

  8. 【swift学习笔记】三.使用xib自定义UITableViewCell

    使用xib自定义tableviewCell看一下效果图 1.自定义列 新建一个xib文件 carTblCell,拖放一个UITableViewCell,再拖放一个图片和一个文本框到tableviewc ...

  9. UITableViewCell的重用机制

    UITabelView一般会显示大量数据,如果有多少条数据就新建多少个cell,那么对于内存来说是种极大的负担,这样自然是不合理的,所以才会有重用机制 比如一个家庭办酒席,一共有13桌,每桌20个菜, ...

  10. iOS UITableViewCell的"滑动出现多个按钮"

    本文授权转载,作者:@夏天是个大人了 前言: 本篇博客其实就是想介绍tableviewcell滑动的一些"事",昨天在逛github的时候看到的还挺有意思的三方库,简单用了一下感觉 ...

随机推荐

  1. jenkins自动化打包报错:gradle: 未找到命令

    shell脚本如下: cd /home/wangju/gitProject/Automation echo "************************开始清理环境********** ...

  2. Jmeter 循环控制器 遍历结果

    1.测试计划,添加Mysql jar包 2.线程组 3.JDBC Connection Configuration,配置Mysql 4.添加JDBC Request,将查询出的数据对应的存入usern ...

  3. Learn Python the hard way, ex39 列表的操作

    #!/usr/bin/python #coding:utf-8 ten_things = "apples oranges crows telephone light sugar" ...

  4. mysql的命令入门

    mysql入门实践 学习教程 教程链接地址 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据. 文 ...

  5. 《JAVA设计模式》之装饰模式(Decorator)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述装饰(Decorator)模式的: 装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替 ...

  6. centos7系统乱码问题解决

    操作步骤: 查看当前系统的默认语言 echo $LANG 查看系统支持的语言库 locale 如果没有要设置的语言需要安装一下 yum groupinstall chinese-support -y ...

  7. mybatis输出映射总结

    使用resultType作为输出映射 只有查询出来的列名和pojo中的属性名一致时,才会映射成功, 如果不一致,可以使用resultMap最为输出类型 不管是输出单个对象还是列表(list中包括poj ...

  8. CVE-2014-4014 Linux Kernel Local Privilege Escalation PoC

    /**  * CVE-2014-4014 Linux Kernel Local Privilege Escalation PoC  *  * Vitaly Nikolenko  * http://ha ...

  9. 排序---快速排序及其切分函数Partition应用

    快速排序   快速排序通过一个切分元素将数组分成两个子数组,左子数组小于等于切分元素,右子数组大于切分元素,将这两个子数组排序,也就是将整个数组排序了. 代码如下: public class Sort ...

  10. vue 中使用 watch 出现了如下的报错

    vue 中使用 watch 出现了如下的报错 报错: Method "watch" has type "object" in the component def ...