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 ...
随机推荐
- markdown 编辑器概述
markdown 编辑器概述 编辑器其实很多很多,主要分为 网页编辑和软件编辑 (效果其实感觉效果差不多,看个人喜好,笔者个人还是喜欢本地,感觉方便挺多的) ## 网页编辑器 主要有 C ...
- python经典算法题目:找出这两个有序数组的中位数
题目:找出这两个有序数组的中位数 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 你可以 ...
- Scrapy进阶知识点总结(六)——中间件详解
概述 查看scrapy官网的框架图,可以看出中间件处于几大主要组件之间,类似于生产流水线上的加工过程,将原料按照不同需求与功能加工成成品 其中4,5处于下载器与引擎之间的就是下载中间件,而spider ...
- Ios第三方FMDB使用说明
SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.iOS SDK很早就支持了SQLite,在使用时,只需要加入 libsqlite3.dyli ...
- 力扣(LeetCode)二进制求和 个人题解
给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11", b = "1" 输出: ...
- 【目标检测实战】目标检测实战之一--手把手教你LMDB格式数据集制作!
文章目录 1 目标检测简介 2 lmdb数据制作 2.1 VOC数据制作 2.2 lmdb文件生成 lmdb格式的数据是在使用caffe进行目标检测或分类时,使用的一种数据格式.这里我主要以目标检测为 ...
- Js获取宽高度的归纳总结
首先,先吓唬一下我们的小白们!在js中的描述宽高的可以细分有22种. window.innerWidth //除去菜单栏的窗口宽度 window.innerHeight//除去菜单栏的窗口高度 win ...
- vim-plug 安装 jedi-vim
安装: Plug 'davidhalter/jedi-vim' :PlugInstall 我就在配置文件里写了一个配置项 let g:jedi#use_tabs_not_buffers = 1 进入定 ...
- [ch03-00] 损失函数
系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 第3章 损失函数 3.0 损失函数概论 3.0.1 概念 ...
- css居中布局的几种方式
一.水平居中 若是行内元素,则直接给其父元素设置text-align: center即可 若是块级元素,则直接给该元素设置margin: 0 auto即可 若子元素包含浮动元素,则给父元素设置widt ...