一:自定义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. Winform GDI+ 相关资料

    在Visual Studio 2010中定义GDI+自定义控件——自定义控件介绍 http://www.cnblogs.com/zhangdong/archive/2010/05/20/1740177 ...

  2. OpenLDAP与Apache

    1:安装部署Apache 2:在/var/www/html下,添加一个测试文件       echo test > index.html          3:在这之前,需了解Apache的账号 ...

  3. PTA Insertion or Heap Sort

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...

  4. for xml 字符串拼接

    SELECT TOP 10 B.user_gid,LEFT(StuList,LEN(StuList)-1) as hobby FROM (SELECT user_gid,( SELECT CAST(a ...

  5. opencv单目摄像机标定(一)

    #include <string> #include <iostream> #include <cv.h> #include <highgui.h> u ...

  6. 记录那些我不清楚的知识点(HTML)

    <div class="link"><a href="http://www.baidu.com/" target="iframeHt ...

  7. Android程序crash处理

    Android程序crash处理 时间 2014-11-24 13:45:37  CSDN博客 原文  http://blog.csdn.net/allen315410/article/details ...

  8. softmax分类器+cross entropy损失函数的求导

    softmax是logisitic regression在多酚类问题上的推广,\(W=[w_1,w_2,...,w_c]\)为各个类的权重因子,\(b\)为各类的门槛值.不要想象成超平面,否则很难理解 ...

  9. Java中四种引用:强、软、弱、虚引用

    这篇文章非常棒:http://alinazh.blog.51cto.com/5459270/1276173 Java中四种引用:强.软.弱.虚引用 1.1.强引用当我们使用new 这个关键字创建对象时 ...

  10. php [] array的区别

    <?php/** * Created by IntelliJ IDEA. * User: Administrator * Date: 2017/1/2 * Time: 17:40 定义数组 ar ...