Figure 5-1 Parts of a table view cell
Figure 5-2 Parts of a table-view cell in editing mode
Figure 5-3 Default cell content in a UITableViewCell object
如上是一个table view cell的组成视图(第二张是编辑状态下的)。
如下是参看iOS源文档整理的UITableViewCell类的属性及方法。
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
Initializes a table cell with a style and a reuse identifier and returns it to the caller.
使用指定的风格和重用ID初始化一个table cell
该方法会在tableView调用dequeueReusableCellWithIdentifier:时被调用
typedef enum : NSInteger {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
} UITableViewCellStyle;
- @property(nonatomic, readonly, copy) NSString *reuseIdentifier
A string used to identify a cell that is reusable. (read-only)
标记一个可复用的cell字符串,只读
- - (void)prepareForReuse
Prepares a reusable cell for reuse by the table view'€™s delegate.
为table view的委托准备一个可复用的cell
该方法会在tableView调用dequeueReusableCellWithIdentifier:方法时在返回cell前被调用,该方法仅可以修改除内容外的cell的属性,如透明度、编辑或选中时的状态等,其他与内容相关的(图片、文本框等)在委托方法
tableView:cellForRowAtIndexPath:中修改
- @property(nonatomic, readonly, retain) UILabel *textLabel
Returns the label used for the main textual content of the table cell. (read-only)
返回cell内容的主要文本框的文本对象,对象
- @property(nonatomic, readonly, retain) UILabel *detailTextLabel
Returns the secondary label of the table cell if one exists. (read-only)
返回cell的第二部分文本对象,只读
当cell风格为UITableViewCellStyleDefault时该属性可忽略
- @property(nonatomic, readonly, retain) UIImageView *imageView
Returns the image view of the table cell. (read-only)
返回cell的图片视图,只读
- @property(nonatomic, readonly, retain) UIView *contentView
Returns the content view of the cell object. (read-only)
返回cell的内容视图,只读
该视图是其他自定义视图的容器,可通过addSubView方法来嵌入自定义视图
- @property(nonatomic, retain) UIView *backgroundView
The view used as the background of the cell.
cell的背景视图
- @property(nonatomic, retain) UIView *selectedBackgroundView
The view used as the background of the cell when it is selected.
cell被选中时的背景视图
- @property(nonatomic, retain) UIView *multipleSelectionBackgroundView
The background view to use for a selected cell when the table view allows multiple row selections.
多行cell被选中时的背景视图
可通过tableView对象的 allowsMultipleSelection属性和allowsMultipleSelectionDuringEditing 属性来使能多行选则
- @property(nonatomic) UITableViewCellAccessoryType accessoryType
The type of standard accessory view the cell should use (normal state).
标准附加视图风格
当accessoryView属性被设置时本属性可被忽略
typedef enum : NSInteger {
UITableViewCellAccessoryNone,
UITableViewCellAccessoryDisclosureIndicator,
UITableViewCellAccessoryDetailDisclosureButton,
UITableViewCellAccessoryCheckmark,
UITableViewCellAccessoryDetailButton
} UITableViewCellAccessoryType;
- @property(nonatomic, retain) UIView *accessoryView
A view that is used, typically as a control, on the right side of the cell (normal state).
cell附加视图
若该属性为nil可通过accessoryType 选择附加视图的显示风格
- @property(nonatomic) UITableViewCellAccessoryType editingAccessoryType
The type of standard accessory view the cell should use in the table view’s editing state.
cell附加视图在编辑状态下的标准风格
当editingAccessoryView被设置时本属性可被忽略
- @property(nonatomic, getter=isSelected) BOOL selected
A Boolean value that indicates whether the cell is selected.
指示cell是否被选中,可设置该属性为YES使cell处在被选中状态(非动画)
- @property(nonatomic) UITableViewCellSelectionStyle selectionStyle
The style of selection for a cell.
cell被选中时的风格
typedef enum : NSInteger {
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray,
UITableViewCellSelectionStyleDefault
} UITableViewCellSelectionStyle;
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
Sets the selected state of the cell, optionally animating the transition between states.
设置cell处在被选中状态,动画方式(可选)
- @property(nonatomic, getter=isHighlighted) BOOL highlighted
A Boolean value that indicates whether the cell is highlighted.
指示cell是否处在高亮的状态,可设置该属性为YES使cell处在高亮状态(非动画)
- - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
Sets the highlighted state of the cell, optionally animating the transition between states.
设置cell处在高亮状态,动画方式(可选)
- @property(nonatomic, getter=isEditing) BOOL editing
A Boolean value that indicates whether the cell is in an editable state.
指示cell是否处在可编辑状态
- - (void)setEditing:(BOOL)editing animated:(BOOL)animated
Toggles the receiver into and out of editing mode.
触发接收者进入或退出编辑模式,动画(可选)
- @property(nonatomic, readonly) UITableViewCellEditingStyle editingStyle
The editing style of the cell. (read-only)
cell编辑风格,只读,默认为 UITableViewCellEditingStyleNone
具体某个cell的风格可在UITableViewDelegate中的方法
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 设置
typedef enum : NSInteger {
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
} UITableViewCellEditingStyle;
- @property(nonatomic, readonly) BOOL showingDeleteConfirmation
Returns whether the cell is currently showing the delete-confirmation button. (read-only)
返回当前cell是否显示“删除-确认”按钮
- @property(nonatomic) BOOL showsReorderControl
A Boolean value that determines whether the cell shows the reordering control.
决定cell是否显示重新排序控件
- - (void)willTransitionToState:(UITableViewCellStateMask)state
Called on the cell just before it transitions between cell states
在cell状态间过渡前调用
typedef enum : NSUInteger {
UITableViewCellStateDefaultMask = 0,
UITableViewCellStateShowingEditControlMask = 1 << 0,
UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1
} UITableViewCellStateMask;
- - (void)didTransitionToState:(UITableViewCellStateMask)state
Called on the cell just after it transitions between cell states.
在cell状态间过渡后调用
- @property(nonatomic) NSInteger indentationLevel
The indentation level of the cell’s content.
cell内容的缩进等级
- @property(nonatomic) CGFloat indentationWidth
The width for each level of indentation of a cell'€™s content.
。。。
- @property(nonatomic) UIEdgeInsets separatorInset
The inset values for the cell’s content.
cell内容的“嵌入”
可使用本属性调整cell内容的左右边界
UITableViewCell类学习
最新推荐文章于 2018-08-04 09:25:44 发布