UITableView 实例详解 滑动编辑 headerView
转自:http://blog.csdn.net/reylen/article/details/8505960
- self.dataArray = [[[NSMutableArray alloc]init] autorelease];
- 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];
- [dataArray addObjectsFromArray:array];
- int height = [UIScreen mainScreen].applicationFrame.size.height;
- self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, height - 40) style:UITableViewStylePlain];
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- [self.view addSubview:self.tableView];
点击 home button,进入编辑

纵向滑动tableCell 出现编辑按钮
- #pragma mark - UITableViewDataSource/Delegate
- //返回table 行数
- - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return dataArray.count;
- }
- - (UITableViewCell*) tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *identifier = @"cell";
- UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
- }
- NSArray *data = [dataArray objectAtIndex:indexPath.row];
- cell.textLabel.text = [data objectAtIndex:0];
- cell.detailTextLabel.text = [data objectAtIndex:1];
- cell.detailTextLabel.textColor = [UIColor redColor];
- return cell;
- }
- //- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- // NSString *headerString = @"Address Price";
- // return headerString;
- //}
- - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
- return @"删除";
- }
- //纵向滑动时响应,出现编辑按钮
- - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
- NSLog(@"Start editing!");
- }
- -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- { //纵向滑动时出现编辑按钮
- return YES;
- }
- //让行可以移动
- -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return YES;
- }
- - (void)tableView:(UITableView *)_tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //编辑完响应事件
- UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
- NSLog(@"title:%@",cell.textLabel.text);
- NSLog(@"price:%@",cell.detailTextLabel.text);
- [dataArray removeObjectAtIndex:indexPath.row];
- [tableView reloadData];
- }
- //设置table headerView
- - (UIView*) tableView:(UITableView *)_tableView viewForHeaderInSection:(NSInteger)section {
- UIView *headerView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, _tableView.frame.size.width, 20)] autorelease];
- UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 20)];
- leftLabel.textColor = [UIColor orangeColor];
- UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(_tableView.frame.size.width - 100, 0, 90, 20)];
- rightLabel.textColor = [UIColor orangeColor];
- leftLabel.text = @"Address";
- rightLabel.text = @"Price";
- rightLabel.textAlignment = NSTextAlignmentRight;
- leftLabel.backgroundColor = [UIColor clearColor];
- rightLabel.backgroundColor = [UIColor clearColor];
- UIImageView *backImage = [[UIImageView alloc]initWithFrame:headerView.frame];
- backImage.image = [UIImage imageNamed:@"back.png"];
- [headerView addSubview:backImage];
- [headerView addSubview:leftLabel];
- [headerView addSubview:rightLabel];
- [leftLabel release];
- [rightLabel release];
- [backImage release];
- return headerView;
- }
UITableView 实例详解 滑动编辑 headerView的更多相关文章
- Cocos2d-x 3.X手游开发实例详解
Cocos2d-x 3.X手游开发实例详解(最新最简Cocos2d-x手机游戏开发学习方法,以热门游戏2048.卡牌为例,完整再现手游的开发过程,实例丰富,代码完备,Cocos2d-x作者之一林顺和泰 ...
- (转载)UITableView使用详解
在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...
- Linux计划任务Crontab实例详解教程
说明:Crontab是Linux系统中在固定时间执行某一个程序的工具,类似于Windows系统中的任务计划程序 下面通过详细实例来说明在Linux系统中如何使用Crontab 操作系统:CentOS ...
- C#实现DevExpress本地化实例详解
using System; using System.Collections.Generic; using System.Text; using DevExpress.XtraGrid.Localiz ...
- 官网实例详解-目录和实例简介-keras学习笔记四
官网实例详解-目录和实例简介-keras学习笔记四 2018-06-11 10:36:18 wyx100 阅读数 4193更多 分类专栏: 人工智能 python 深度学习 keras 版权声明: ...
- linux基础-磁盘阵列(RAID)实例详解
磁盘阵列(RAID)实例详解 raid技术分类 软raid技术 硬raid技术 Raid和lvm的区别 为什么选择用raid RAID详解 RAID-0 RAID-1 RAID-5 Raid-10 R ...
- JavaScript学习笔记-实例详解-类(二)
实例详解-类(二) //===给Object.prototype添加只读\不可枚举\不可配置的属性objectId(function(){ Object.defineProperty(Object ...
- JavaScript学习笔记-实例详解-类(一)
实例详解-类(一): //每个javascript函数(除了bind())都自动拥有一个prototype对象// 在未添加属性或重写prototype对象之前,它只包含唯一一个不可枚举属性const ...
- Entity Framework实例详解
Entity Framework Code First的默认行为是使用一系列约定将POCO类映射到表.然而,有时候,不能也不想遵循这些约定,那就需要重写它们.重写默认约定有两种方式:Data Anno ...
随机推荐
- setAccessible()方法
在java代码中,我们经常使用private来控制类中成员变量的访问权限,在类的外边我们一般使用get方法获取私有成员变量的值,但是如果类中没有get方法,但我们又想获取该类私有成员变量的值,该怎么办 ...
- 深入理解计算机系统 第二章 信息的表示和处理 Part2 第二遍
<深入理解计算机系统> 第三版 第二遍读这本书,每周花两到三小时时间,能读多少读多少(这次看了 29 ~ 34 页) 第一遍对应笔记链接 https://www.cnblogs.com/s ...
- T-SQL Part VIII: CROSS APPLY, OUTER APPLY
除了CROSS JOIN, INNER JOIN, OUTER JOIN之外,T-SQL还提供了CROSS APPLY和OUTER APPLY这两个较为另类的Set操作符. 首先来看CROSS APP ...
- 【搞定 Java 并发面试】面试最常问的 Java 并发基础常见面试题总结!
本文为 SnailClimb 的原创,目前已经收录自我开源的 JavaGuide 中(61.5 k Star![Java学习+面试指南] 一份涵盖大部分Java程序员所需要掌握的核心知识.欢迎 Sta ...
- 🙈羞,Spring Bean 初始化/销毁竟然有这么多姿势
文章来源:http://1t.click/bfHN 一.前言 日常开发过程有时需要在应用启动之后加载某些资源,或者在应用关闭之前释放资源.Spring 框架提供相关功能,围绕 Spring Bean ...
- K8s & Openshift案例学习
1. openshift排错技巧:https://mp.weixin.qq.com/s?__biz=MzAwMDc2NjQ4Nw==&mid=2663494178&idx=1& ...
- Flex实现web版图片查看器
项目需求: 在web端实现图片浏览,具有放大.缩小.滚轴放大缩小.移动.旋转以及范围控制. 成果图:
- python3 之 判断闰年小实例
一.方法1: while True: try: year = int(input('请输入一个年份:')) if (year % 4) == 0 and (year % 100) != 0 or (y ...
- 新闻实时分析系统 大数据Web可视化分析系统开发
1.基于业务需求的WEB系统设计 2.下载Tomcat并创建Web工程并配置相关服务 下载tomcat,解压并启动tomcat服务. 1)新建web app项目 创建好之后的效果 2)对tomcat进 ...
- java之初见
1.Java语言的了解: Java语言最早是由SUN公司创造出来的,1991年,SUN公司的green项目,Oak,随后SUN公司和后来的甲骨文公司又先后发布了java1.0,1.1,1.2,1.3, ...