UITableViewCell定制总结
来源:互联网 发布:c语言输出图案 编辑:程序博客网 时间:2024/06/10 08:06
介绍TableView非常不错的一篇文章:
http://www.cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
官方给出的cell的讲解:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html
误区:
if(cell ==nil)
{
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellId]autorelease];
cell.backgroundColor = [UIColorgreenColor];
}
return cell;
这样设置cell的背景通常是不起作用的,纳尼?!淡定,需要了解一下cell的组成。backgroundView
— the entire background of the row (including what looks like theUITableView
's background inUITableViewStyleGrouped
style tables 整个的行的背景视图selectedBackgroundView
— replaces thebackgroundView
when the row is selected. 选中cell后的背景视图,替换原有的背景视图image
— a customizable image (not actually a subview) at the left of the cell.一个定制的image位于cell的左侧accessoryView
— a customizable view at the right of the cell. 一个定制的view位于cell的右侧contentView
— a customizable view between theimage
and theaccessoryView
(technically, it extends behind theimage
).
contentView是cell的一个子View,要明确这一点!!
(PS:值得注意的是tableView除了可以自定义背景颜色之外,不可以自定义北京,像自定义背景必须把tableView的背景色置为clear,然后定义tableView上一层的view的背景)
A cell object has various parts, which can change depending on the mode of the table view.
官方给的解释说:cell对象有多重组成部分,可以根据tableView的模式而变化.
只有cell位于UITableViewCellStyleSubtitle模式下。下面的detailTextLabel才会起作用.
textLabel
—A label for the title (aUILabel
object)detailTextLabel
—A label for the subtitle if there is additional detail (aUILabel
object)imageView
—An image view for an image (aUIImageView
object)
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellId]autorelease];
cell.accessoryType =UITableViewCellAccessoryDetailDisclosureButton;
cell.textLabel.text =@"1";
cell.detailTextLabel.text =@"2";
cell.imageView.image = [UIImageimageNamed:@"1"];
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellId]autorelease];
cell.accessoryType =UITableViewCellAccessoryDetailDisclosureButton;
cell.textLabel.text =@"1";
cell.detailTextLabel.text =@"2";
// cell.imageView.image = [UIImage imageNamed:@"1"];
文字是顶边的。
不过可以改变indentationLevel去使得文字不再顶边
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryType =UITableViewCellAccessoryDetailDisclosureButton;
cell.textLabel.text =@"1safdasfasfsafas";
cell.detailTextLabel.text =@"2";
cell.indentationLevel =2;
cell.indentationWidth =5;//缩进距离为2*5=10 默认的宽度为10...
cell.imageView.image = [UIImageimageNamed:@"1"];
自定义cell的两种方式:(具体的定制方式,官方都有给出,很详细还有具体代码可以看)
Add subviews to a cell’s content view.注意是加view时加到了contentView上面.
- 1、可以使用tag的方式,放到xib里面加
- 2、也可以直接采用程序实现,用tag获取到cell里的东西
Create a custom subclass of
UITableViewCell
.
注意:使用xib自定义的时候要 Enter a reuse identifier in the Identifier text field!!!
关于tableView的性能问题(官方给出三点建议):
Reuse cells. Object allocation has a performance cost, especially if the allocation has to happen repeatedly over a short period—say, when the user scrolls a table view. If you reuse cells instead of allocating new ones, you greatly enhance table view performance.
Avoid relayout of content. When reusing cells with custom subviews, refrain from laying out those subviews each time the table view requests a cell. Lay out the subviews once, when the cell is created.
Use opaque subviews. When customizing table view cells, make the subviews of the cell opaque, not transparent.
- UITableViewCell定制总结
- 定制UITableViewCell
- 定制UITableViewCell
- UITableViewCell定制
- UITableViewCell定制
- UITableViewCell accessory 定制
- 定制 UITableViewCell 表视图单元格
- 表格UITableViewCell定制和使用
- 代码实现UITableViewCell表视图单元定制
- Table Views(中)UITableViewCell定制
- 代码实现UITableViewCell表视图单元定制
- Table Views(中)UITableViewCell定制
- 定制可隐藏seperator的UITableViewCell
- UITableViewCell左滑button的定制
- iOS学习 UITableViewCell 三种定制方法
- 一些关于uitableviewcell的总结
- 使用XIB文件来定制你的UITableViewCell
- [iOS开发必备技巧之]使用IB定制UITableViewCell
- OpenCV 4.4 习题解答
- 织梦同一页面调用多个相同的js联动菜单
- 关于android中spinner级联问题
- 剑指offer
- python3中替换python2中cmp函数的新函数分析(lt、le、eq、ne、ge、gt)
- UITableViewCell定制总结
- linux 线程常用函数
- C# asp.net页面通过URL参数传值中文乱码问题解决办法
- PE文件代码段的加密与解密
- Handler sendMessage 与 obtainMessage (sendToTarget)比较
- 嵌入式面试题
- 一点一点培养你的领袖气质
- Chap 5 习题解答
- jquery平滑滚动插件