一:自定义UITableViewCell:

先来看UITableView.h:

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

- (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

- (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

大意是从iOS 6开始,我们能够为每个Cell注册一个nib文件或类,实现自定义Cell。

主要来看一下如何调用Cell.xib文件:

保证自定义Cell.xib文件identifier属性与使用该nib文件时给予的参数CellIdentifier一致,可通过

[tableView registerNib:[UINibnibWithNibName:@"Cell"bundle:nil] forCellReuseIdentifier:CellIdentifier];

来注册该nib文件,即可。

二:

UITableViewCell.h的一些自定义外观的属性:

@property(nonatomic,readonly,retain) UIImageView  *imageView NS_AVAILABLE_IOS(3_0);   // 默认为nil,必要时创建

@property(nonatomic,readonly,retain) UILabel      *textLabel NS_AVAILABLE_IOS(3_0);   //  默认为nil,必要时创建

@property(nonatomic,readonly,retain) UILabel      *detailTextLabel NS_AVAILABLE_IOS(3_0); //  默认为nil,必要时创建(UITableViewStyle支持的情况下)

@property(nonatomic,readonly,retain) UIView       *contentView; //内容视图;给Cell添加自己的视图时,添加到contentView中,这样可以在其他情况下保证视图定位的准确性

@property(nonatomic,retain) UIView                *backgroundView; //背景视图

@property(nonatomic,retain) UIView                *selectedBackgroundView;

// If not nil, takes the place of the selectedBackgroundView when using multiple selection.

@property(nonatomic,retain) UIView                *multipleSelectionBackgroundView NS_AVAILABLE_IOS(5_0);

@property(nonatomic,readonly,copy) NSString       *reuseIdentifier;//重用的Cell身份标记

@property(nonatomic) UITableViewCellSelectionStyle  selectionStyle;             //Cell被选中时的状态,默认是UITableViewCellSelectionStyleBlue.

@property(nonatomic,readonly) UITableViewCellEditingStyle editingStyle;         // 默认是UITableViewCellEditingStyleNone.使用委托的值设置外观

因此,设置Cell的外观如背景时,应当设置Cell的contentView的背景颜色。

UITableViewCell和UITableView的学习的更多相关文章

  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath不执行的问题

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa ...

  2. UITableViewCell嵌套UITableView的正确姿势

    内嵌UiTableView的高度计算起来太麻烦了,如何解决,就是把二级TableVIew里面的model item做到一级,然后对不同的item类型做不同的Cell,这样就Ok了.给一个得到Cell的 ...

  3. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;方法意思

    这个方法是用来设置你的TableView中每一行显示的内容和格式的. indexPath 用来指示当前单元格,它的row方法可以获得这个单元格的行号,section方法可以获得这个单元格所处的区域号 ...

  4. iPhone应用开发 UITableView学习点滴详解

    iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容. -.建立 UITableView DataTab ...

  5. UITableView 学习笔记

    http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html UITableView学习笔记 作者:一片枫叶 看TableVi ...

  6. iOS深入学习(UITableView系列4:使用xib自定义cell)

    可以通过继承UITableViewCell重新自定义cell,可以像下面一样通过代码来自定义cell,但是手写代码总是很浪费时间, ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  7. iOS深入学习(UITableView系列2:reloadData)

    接着前一篇的博客来深入学习UITableView, UITableView的数据源是NSMutableArray的对象_infoArray,现在数组的内容为{@"Zero",@&q ...

  8. (转)IOS UITableView学习

    转自:http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html          作者:一片枫叶 看TableView的资 ...

  9. UITableView学习笔记

    //非原创 看TableView的资料其实已经蛮久了,一直想写点儿东西,却总是因为各种原因拖延,今天晚上有时间静下心来记录一些最近学习的TableView的知识.下面进入正题,UITableView堪 ...

随机推荐

  1. vim的共享系统剪贴板以及缩进相关问题

    http://www.cnblogs.com/end/archive/2012/06/01/2531147.html:reg 可以显示可用的寄存器,其中注意两个特殊的寄存器:"* 和 &qu ...

  2. tesseract-ocr

    tesseract-ocr 第一课 前言 据网上介绍tesseract-ocr性能不错,并且可以支持识别中文了.于是尝试一下.   安装 1.下载地址: https://code.google.com ...

  3. shell获取ip

    ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"

  4. Zend Studio

    下载地址:http://www.zend.com/en/products/studio/downloads#Windows 详情:http://baike.baidu.com/link?url=8rX ...

  5. Android Studio开发基础之自定义View组件

    一般情况下,不直接使用View和ViewGroup类,而是使用使用其子类.例如要显示一张图片可以用View类的子类ImageView,开发自定义View组件可分为两个主要步骤: 一.创建一个继承自an ...

  6. 树莓派配置文档 config.txt 说明(转)

    原文连接:http://elinux.org/RPi_config.txt 由于树莓派并没有传统意义上的BIOS, 所以现在各种系统配置参数通常被存在"config.txt"这个文 ...

  7. PTA Strongly Connected Components

    Write a program to find the strongly connected components in a digraph. Format of functions: void St ...

  8. SQL Server 导出数据到 PostgreSQL

    乘着倒数据这会儿,把方法记录一下 需求:因为数据迁移,需要将SQL Server 2012中的数据库导入到PostgreSQL 数据库中 思路:创建一个空的数据库,便于导入数据.下载PostgreSQ ...

  9. 网页链接qq

    <a href="mqqwpa://im/chat?chat_type=wpa&uin=12345678&version=1&src_type=web& ...

  10. 火狐通行证升级为Firefox Sync后,如何在多设备间同步书签等信息

    一直在使用Firefox的一个比较重要的原因是习惯了它的书签同步功能,之前一直是使用火狐通行证来实现多设备间同步的,最近新装了WIN8.1系统来学习,结果装上新版Firefox之后,发现无论怎么弄也没 ...