转自:http://blog.csdn.net/reylen/article/details/8505960

  1. self.dataArray = [[[NSMutableArray alloc]init] autorelease];
  2. NSArray *array = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"Beijing",@"$500", nil],[NSArray arrayWithObjects:@"ShangHai",@"$510", nil],[NSArray arrayWithObjects:@"Guangzhou",@"$540", nil],[NSArray arrayWithObjects:@"Wuhan",@"$513", nil], nil];
  3. [dataArray addObjectsFromArray:array];
  4. int height = [UIScreen mainScreen].applicationFrame.size.height;
  5. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, height - 40) style:UITableViewStylePlain];
  6. self.tableView.dataSource = self;
  7. self.tableView.delegate = self;
  8. [self.view addSubview:self.tableView];

点击 home button,进入编辑

                         

纵向滑动tableCell 出现编辑按钮

  1. #pragma mark - UITableViewDataSource/Delegate
  2. //返回table 行数
  3. - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  4. return dataArray.count;
  5. }
  6. - (UITableViewCell*) tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  7. static NSString *identifier = @"cell";
  8. UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:identifier];
  9. if (cell == nil) {
  10. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  11. }
  12. NSArray *data = [dataArray objectAtIndex:indexPath.row];
  13. cell.textLabel.text = [data objectAtIndex:0];
  14. cell.detailTextLabel.text = [data objectAtIndex:1];
  15. cell.detailTextLabel.textColor = [UIColor redColor];
  16. return cell;
  17. }
  18. //- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  19. //    NSString *headerString = @"Address                                   Price";
  20. //    return headerString;
  21. //}
  22. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  23. return @"删除";
  24. }
  25. //纵向滑动时响应,出现编辑按钮
  26. - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
  27. NSLog(@"Start editing!");
  28. }
  29. -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  30. {        //纵向滑动时出现编辑按钮
  31. return YES;
  32. }
  33. //让行可以移动
  34. -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  35. {
  36. return YES;
  37. }
  38. - (void)tableView:(UITableView *)_tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {      //编辑完响应事件
  39. UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
  40. NSLog(@"title:%@",cell.textLabel.text);
  41. NSLog(@"price:%@",cell.detailTextLabel.text);
  42. [dataArray removeObjectAtIndex:indexPath.row];
  43. [tableView reloadData];
  44. }
  45. //设置table headerView
  46. - (UIView*) tableView:(UITableView *)_tableView viewForHeaderInSection:(NSInteger)section {
  47. UIView *headerView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, _tableView.frame.size.width, 20)] autorelease];
  48. UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 20)];
  49. leftLabel.textColor = [UIColor orangeColor];
  50. UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(_tableView.frame.size.width - 100, 0, 90, 20)];
  51. rightLabel.textColor = [UIColor orangeColor];
  52. leftLabel.text = @"Address";
  53. rightLabel.text = @"Price";
  54. rightLabel.textAlignment = NSTextAlignmentRight;
  55. leftLabel.backgroundColor = [UIColor clearColor];
  56. rightLabel.backgroundColor = [UIColor clearColor];
  57. UIImageView *backImage = [[UIImageView alloc]initWithFrame:headerView.frame];
  58. backImage.image = [UIImage imageNamed:@"back.png"];
  59. [headerView addSubview:backImage];
  60. [headerView addSubview:leftLabel];
  61. [headerView addSubview:rightLabel];
  62. [leftLabel release];
  63. [rightLabel release];
  64. [backImage release];
  65. return headerView;
  66. }
 
 

UITableView 实例详解 滑动编辑 headerView的更多相关文章

  1. Cocos2d-x 3.X手游开发实例详解

    Cocos2d-x 3.X手游开发实例详解(最新最简Cocos2d-x手机游戏开发学习方法,以热门游戏2048.卡牌为例,完整再现手游的开发过程,实例丰富,代码完备,Cocos2d-x作者之一林顺和泰 ...

  2. (转载)UITableView使用详解

    在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...

  3. Linux计划任务Crontab实例详解教程

    说明:Crontab是Linux系统中在固定时间执行某一个程序的工具,类似于Windows系统中的任务计划程序 下面通过详细实例来说明在Linux系统中如何使用Crontab 操作系统:CentOS ...

  4. C#实现DevExpress本地化实例详解

    using System; using System.Collections.Generic; using System.Text; using DevExpress.XtraGrid.Localiz ...

  5. 官网实例详解-目录和实例简介-keras学习笔记四

    官网实例详解-目录和实例简介-keras学习笔记四 2018-06-11 10:36:18 wyx100 阅读数 4193更多 分类专栏: 人工智能 python 深度学习 keras   版权声明: ...

  6. linux基础-磁盘阵列(RAID)实例详解

    磁盘阵列(RAID)实例详解 raid技术分类 软raid技术 硬raid技术 Raid和lvm的区别 为什么选择用raid RAID详解 RAID-0 RAID-1 RAID-5 Raid-10 R ...

  7. JavaScript学习笔记-实例详解-类(二)

    实例详解-类(二)   //===给Object.prototype添加只读\不可枚举\不可配置的属性objectId(function(){ Object.defineProperty(Object ...

  8. JavaScript学习笔记-实例详解-类(一)

    实例详解-类(一): //每个javascript函数(除了bind())都自动拥有一个prototype对象// 在未添加属性或重写prototype对象之前,它只包含唯一一个不可枚举属性const ...

  9. Entity Framework实例详解

    Entity Framework Code First的默认行为是使用一系列约定将POCO类映射到表.然而,有时候,不能也不想遵循这些约定,那就需要重写它们.重写默认约定有两种方式:Data Anno ...

随机推荐

  1. mpvue+小程序云开发,纯前端实现婚礼邀请函

    请勿使用本文章及源码作为商业用途! 前言 当初做这个小程序是为了婚礼前的需要,结婚之后,希望这个小程序能够留存下来,特地花了一些空闲时间将小程序转化成为“相册类小程序” 体验码 准备工作 mpvue框 ...

  2. JVM浅谈

    **前言** 由于先前也遇到过一些性能问题,OOM算是其中的一大类了.因此也对jvm产生了一些兴趣.自己对jvm略做了些研究.后续继续补充. **从oom引申出去** 既然说到oom,首先需要知道oo ...

  3. CMake 常用函数记录

    1.cmake_minunum_required(VERSION 2.6) #cmake 最低要求版本号 2.PROJECT(projectname [CXX] [C] [Java]) #这个指令隐式 ...

  4. MAC系统下,Jmeter5.1.1 无法录制问题

    问题一: 点击[start]先出现一个检查证书信息的弹窗,确保删除旧的安装新的,并且需要信任证书 (一般证书只需要信任一下即可,每次启动都会有这个弹窗提醒) 问题二: MAC OS系统使用Jmeter ...

  5. fiddler工具使用大全

    Fiddler基础知识 Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的,使用的代理地址是:127.0.0.1,端口默认为8888,我们也可以通过设置进行修改. 代理就是在 ...

  6. shodan 文档学习笔记

    Table of Contents 1. Introduction 1.1. All About the Data 1.2. Data Collection 1.3. SSL in Depth 1.3 ...

  7. VMware NAT模式ping通外网[CentOS7]

    使用一张网卡,NAT模式 在编辑里打开虚拟网络编辑器 dhcp设置的范围 你的虚拟机的IP 就在那个范围里 NAT设置里有填网关 这里我们vmware 的设置就OK了 在去把你的网络适配器改下iP 这 ...

  8. error: Unexpected console statement (no-console)

    使用console.log 报错??这个错误是Vuejs - 使用ESLint检查代码而产生的 解决办法: 1.不处理,虽然有恼人的提示,但是实际上能使用console.log的 2.关掉ESLint ...

  9. ASP使用ajax来传递中文参数的编码处理

    背景 asp的第一版是0.9测试版,自从1996年ASP1.0诞生,迄今20余载.虽然asp在Windows2000 IIS服务5.0所附带的ASP 3.0发布后好像再没有更新过了,但是由于其入手简单 ...

  10. php为什么要用swoole?

    最近两个月一直在研究 Swoole,那么借助这篇文章,我希望能够把 Swoole 安利给更多人.虽然 Swoole 可能目前定位是一些高级 phper 的玩具,让中低级望而生畏,可能对一些应用场景也一 ...