UITabelViewCell自定义(zhuan)
// 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MyCell";
// 自定义cell
MyCell *cell = (MyCell *)[tableVie dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
// 这种方式,将会查找响应的xib文件,将不会调用initWithStyle方法
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:nil options:nil];
cell = [array objectAtIndex:0];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MyCell";
// 自定义cell
MyCell *cell = (MyCell *)[tableVie dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
// 这种方式,将会调用cell中的initWithStyle方法
cell = [[[MyCell alloc] initWithStyle:UITableViewCellSelectionStyleGray reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
cell.accessoryType = UITableViewCellAccessoryNone;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(0.0, 0.0, 55, 57)];
[button setImage:[UIImage imageNamed:@"tap_normal.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"tap_highlight.png"] forState:UIControlStateHighlighted];
[button setTag:indexPath.row];
[button addTarget:self action:@selector(doClickPlaybillAction:event:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundColor:[UIColor clearColor]];
[cell setAccessoryView:button];
return cell;
@property(nonatomic) UITableViewCellAccessoryType accessoryType;
@property(nonatomic,retain) UIView *accessoryView;
@property(nonatomic) UITableViewCellAccessoryType editingAccessoryType;
@property(nonatomic,retain) UIView *editingAccessoryView;
- (void) performExpand:(id)paramSender{
UITableViewCell *ownerCell = (UITableViewCell*)[paramSender superview];// 获得父视图,即TableViewCell
if (ownerCell != nil){
NSIndexPath *ownerCellIndexPath = [self.myTableView indexPathForCell:ownerCell];
NSLog(@"Accessory in index path is tapped. Index path = %@", ownerCellIndexPath);
}
}
通过,上面一步,我们为Cell添加了一个自定义的按钮。
也许就会遇到这么一个纠结的情况,当点击UITableViewCell高亮时,其子视图中不该高亮的对象(比如说自定义的那个按钮)也高亮了。
比如:
正确方式:我们需要cell被选中时,按钮不应该也被高亮显示。如:
错误方式:但是,cell被选中时,按钮却也高亮显示了。如:
-
(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[super setHighlighted:highlighted animated:animated];
if(highlighted) {
[(UIButton
*)self.accessoryView setHighlighted:NO];
}
}
-
(void)setSelected:(BOOL)selected animated:(BOOL)animated{
[super setSelected:selected animated:animated];
if(selected) {
[(UIButton
*)self.accessoryView setHighlighted:NO];
}
}
因为当UITableViewCell为选中状态时,UITableViewCell把selectedBackgroundView当作一个子视图来添加;
selectedBackgroundView被添加在UITableViewCell的backgroundView之上,或者所有其它视图之下。
当调用setSelected:
animated:这一方法时,会导致selectedBackgroundView以一个alpha消化的状态来出现和消失。
还应该注意:
UITableViewCell的selectionStyle值为UITableViewCellSelectionStyleNone时,selectedBackgroundView将不起作用。
// 设置背景
UIImageView *bgImage=[[[UIImageView alloc] initWithFrame:CGRectMake(0,
0, 320,
57)] autorelease];
[bgImage setImage: [UIImage imageNamed:@"table_live_bg.png"]];
[self
setBackgroundView:bgImage];
[self setBackgroundImageByName:@"table_live_bg.png"];
[self setBackgroundImage:[UIImage imageNamed:@"table_live_bg.png"]];
[self.contentView insertSubview:messageBackgroundView
belowSubview:self.textLabel];
self.selectionStyle =
UITableViewCellSelectionStyleNone;
//定制Delete字符串,添加函数
返回要显示的字符串
-(NSString
*)tableView:(UITableView*)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}
UITabelViewCell自定义(zhuan)的更多相关文章
- ios之UITabelViewCell的自定义(xib实现2)
上篇文章介绍了如何用UITableView显示表格,并讲了几种UITableViewCell的风格.不过有时候我们需要自己定义 UITableViewCell的风格,其实就是向行中添加子视图.添加子视 ...
- ios之UITabelViewCell的自定义(xib实现)
通过继承UITableViewCell来自定义cell 1.创建一个空的项目.命名: 2.创建一个UITableViewController 并且同时创建xib: 3.设置AppDelegate.m中 ...
- ios之UITabelViewCell的自定义(代码实现)
在用到UITableVIew的时候,经常会自定义每行的Cell 在IOS控件UITableView详解中的下面代码修改部分代码就可以实现自定义的Cell了 [cpp] view plaincopy - ...
- UITabelView 高级(自定义Cell)
自定义一个Cell 当我们要显示复杂数据的时候,例如要做一个扣扣聊天界面,或是新闻列表,系统的行已经不能满足我们的要求,这个时候我们可以通过自定义这个行,让他显示更多复杂结构的样式. 自定义cell就 ...
- vue通过自定义指令 v-py 将名字转拼音
自定义指令 py: 1.新建 vue-py.js文件 import Vue from 'vue'; var chinesePointCode = { "a": [21834, 38 ...
- MySQL从删库到跑路_高级(二)——自定义函数
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.自定义函数简介 自定义函数(user-defined function UDF)是一种对MySQL扩展的途径,其 ...
- 关于Unity3D自定义编辑器的学习
被人物编辑器折腾了一个月,最终还是交了点成品上去(还要很多优化都还么做). 刚接手这项工作时觉得没概念,没想法,不知道.后来就去看<<Unity5.X从入门到精通>>中有关于 ...
- 一起学微软Power BI系列-使用技巧(5)自定义PowerBI时间日期表
1.日期函数表作用 经常使用Excel或者PowerBI,Power Pivot做报表,时间日期是一个重要的纬度,加上做一些钻取,时间日期函数表不可避免.所以今天就给大家分享一个自定义的做日期表的方法 ...
- JavaScript自定义浏览器滚动条兼容IE、 火狐和chrome
今天为大家分享一下我自己制作的浏览器滚动条,我们知道用css来自定义滚动条也是挺好的方式,css虽然能够改变chrome浏览器的滚动条样式可以自定义,css也能够改变IE浏览器滚动条的颜色.但是css ...
随机推荐
- 【Treap】BZOJ1588-[HNOI2002]营业额统计
[题目大意][借用别人的概括]给出一个n个数的数列a,对于第i个元素ai定义fi=min(abs(ai-aj)),(1<=j<i),其中f1=a1.输出sum(fi) (1<=i&l ...
- iOS 修改APP工程名字
我们在iOS开发中,难免会遇到项目做到一半要改名字的情况.如果项目名差的太大,工程名看起来总是不舒服的,就会想着为工程改个贴切的名字,那么你就为用到本文记录的内容. 如何修改工程名呢? 下面我就拿一个 ...
- [shell 编程] if [ $# -eq 0 ]该语句是什么含义?
$0: shell或shell脚本的名字$*:以一对双引号给出参数列表$@:将各个参数分别加双引号返回$#:参数的个数$_:代表上一个命令的最后一个参数$$:代表所在命令的PID$!:代表最后执行的后 ...
- javascript快速入门19--定位
元素尺寸 获取元素尺寸可以使用下面几种方式 元素的style属性width,height,但这些属性往往返回空值,因为它们只能返回使用行内style属性定义在元素上的样式 元素的currentStyl ...
- 为Linux上FireFox安装Flash插件
废话少说,步骤如下: 1.点击网页上插件缺失处,根据提示下载tar.gz版本的插件,我下载的版本是install_flash_player_11_linux.i386.tar.gz,这个文件被下载到了 ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何查询某个变量的ADS地址
鼠标放到任意一个参数上停留一段时间,会自动弹出关于该条参数的ADS信息 TC3也是一样(如果不是轴的某个参数而是PLC程序绑定的某个变量也是一样,定位到这个变量既可以看到ADS信息) ...
- [转载]Android开发者必须深入学习的10个应用开源项目
[转载]Android开发者必须深入学习的10个应用开源项目 原文地址:Android开发者必须深入学习的10个应用开源项目(http://blog.sina.com.cn/s/blog_7b8a63 ...
- python——3.x的异常处理 请注意了
以前的python2.x的时候:try: fp=urllib.request.urlopen(blogurl) except Exception, e: print ...
- 微信小程序页面跳转
一:跳转的数据传递 例如:wxml中写了一个函数跳转: [html] view plain copy <view class="itemWeight" catchtap=&q ...
- jsp+servlet实现文件上传
上传(上传不能使用BaseServlet) 1. 上传对表单限制 * method="post" * enctype="multipart/form-data" ...