iOS组件之UITableViewCell详解

引言

UITableViewCell继承于UIView(有关UIControl请参照《iOS组件之UIView详解》),UITableViewCell类定义出现在UITableView中对象的单元格的属性和行为。这个类包含的属性和设置和管理的单元格内容和背景(包括文字,图片,和自定义视图) ,管理小区选择并高亮显示状态,管理配套的看法,以及发起的单元格内容的编辑方法。

当创建单元格,你可以自己自定义它们,或者使用几个预定义样式之一。预定义的单元格样式是最简单的选择。与预定义样式,单元格提供标签和图像子视图的位置和造型是固定的。所有您需要做的是提供文本和图像内容进入那些固定的看法。要使用单元格与预定义的风格,采用了initWithStyle初始化: reuseIdentifier :方法或将单元配置与风格在Xcode 。要设置单元格的文本和图像,使用为textLabel , detailTextLabel和ImageView的属性。

目录

1、基本属性及方法

1、基本属性及方法

// 初始化方法

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;

// cell上默认图片显示view,(默认为nil,当需要的时候才会被创建)

UIImageView *imageView;

// cell上默认的UILabel(默认为nil,当需要的时候才会被创建)

UILabel     *textLabel;

// cell简介(默认为nil,如果当前的style支持的话需要时将会被创建)

UILabel     *detailTextLabel;

// 与cell自带的删除按钮平级的view

UIView *contentView;

// 背景view

UIView *backgroundView;

// 多选时的背景view

UIView *multipleSelectionBackgroundView;

// cell的标识符

NSString *reuseIdentifier;

// 重用cell时会调用这个函数

- (void)prepareForReuse; 

// 选中时的cell样式(默认为UITableViewCellSelectionStyleBlue)

UITableViewCellSelectionStyle   selectionStyle; 

// 是否选中

BOOL         selected; 

// 是否高亮

BOOL      highlighted;

// 设置cell为选中状态

- (void)setSelected:(BOOL)selected animated:(BOOL)animated;                  

// 设置为高亮状态

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;

// 设置cell的编辑样式

UITableViewCellEditingStyle editingStyle;

// showsReorderControl = YES时Cell显示移动按钮(默认为NO)

BOOL showsReorderControl;        // default is NO

// 没有出现delete控件和行头控件,可cell的宽度还是变了,有没有办法使cell在edit模式下,宽度不改变

BOOL shouldIndentWhileEditing;

// 设置cell的样式

UITableViewCellAccessoryType accessoryType;

UITableViewCellAccessoryNone;//cell没有任何的样式

UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;

UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;

UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;

// 除此上面之外,如果你想使用自定义附件按钮的其他样式,必需使用UITableView的accessoryView属性

UIView *accessoryView;

// 设置当cell进入编辑模式时的辅助按钮样式

UITableViewCellAccessoryType editingAccessoryType;

// 自定义cell进入编辑模式后辅助按钮

UIView *editingAccessoryView;       

// 获取cell的缩进级别

NSInteger indentationLevel;           

// 获取cell的缩进宽度

CGFloat indentationWidth;

// 设置是否处于编辑模式

BOOL           editing;

// 设置编辑模式

- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

// 当前是否显示delete按钮

BOOL showingDeleteConfirmation;  // currently showing "Delete" button

// 这两个方法应该在子类中覆写,当前Cell的状态发生改变的时刻就会触发这些方法,可以在这些方法中进行一些额外的操作。(例如:cell被点击以后就会进入UITableViewCellStateShowingDeleteConfirmationMask 状态)

- (void)willTransitionToState:(UITableViewCellStateMask)state;
- (void)didTransitionToState:(UITableViewCellStateMask)state;





Comments