##简介 An instance of UITableView (or simply, a table view) is a means for displaying and editing hierarchical lists of information.
UITableView的实例(或者只是表视图)是一个用于显示和编辑的分层列表信息。
初始化一个UITableView对象
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
// UITableViewStyle的定义:
typedef enum {
UITableViewStylePlain,//一个普通的表视图。任何一节表头和表尾显示为内联分隔符和浮动当滚动表格视图。
UITableViewStyleGrouped // 部分的表视图呈现截然不同的分组里面
} UITableViewStyle;
##常用方法和属性
配置图表参数
@property(nonatomic, readonly) UITableViewStyle style;
style Property;
// 每一组有多少行数据
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
// 当前tableView里有多少section,默认为1
numberOfSections Property
// 行高
rowHeight Property
// 分隔线属性
separatorStyle Property
separatorColor Property
separatorEffect Property
// tableview的背景
backgroundView Property
separatorInset Property
cellLayoutMarginsFollowReadableWidth Property
创建单元格
- registerNib:forCellReuseIdentifier:
- registerClass:forCellReuseIdentifier:
- dequeueReusableCellWithIdentifier:forIndexPath:
- dequeueReusableCellWithIdentifier:
设置表头和表尾
- registerNib:forHeaderFooterViewReuseIdentifier:
- registerClass:forHeaderFooterViewReuseIdentifier:
- dequeueReusableHeaderFooterViewWithIdentifier:
tableHeaderView Property
tableFooterView Property
sectionHeaderHeight Property
sectionFooterHeight Property
- headerViewForSection:
- footerViewForSection:
设置单元格和Sections
// 每一行显示什么内容
//每当有一个cell进入视野屏幕就会调用,所以在这个方法内部就需要优化。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(cell==nil){
//在这里面做创建的工作。循环优化。防止刷新cell进入屏幕的时候重复的创建
}
}
//当调用reloadData的时候,会重新刷新调用数据源内所有方法,其他事情都不会做呀
[self reloadData]
- indexPathForCell:
- indexPathForRowAtPoint:
- indexPathsForRowsInRect:
visibleCells Property
indexPathsForVisibleRows Property
估计元素高度
estimatedRowHeight Property
estimatedSectionHeaderHeight Property
estimatedSectionFooterHeight Property
滚动表视图
- scrollToRowAtIndexPath:atScrollPosition:animated:
- scrollToNearestSelectedRowAtScrollPosition:animated:
管理选择
indexPathForSelectedRow Property
indexPathsForSelectedRows Property
- selectRowAtIndexPath:animated:scrollPosition:
- deselectRowAtIndexPath:animated:
allowsSelection Property
allowsMultipleSelection Property
allowsSelectionDuringEditing Property
allowsMultipleSelectionDuringEditing Property
插入、删除、移动单元格和Sections
- beginUpdates
- endUpdates
- insertRowsAtIndexPaths:withRowAnimation:
- deleteRowsAtIndexPaths:withRowAnimation:
- moveRowAtIndexPath:toIndexPath:
- insertSections:withRowAnimation:
- deleteSections:withRowAnimation:
- moveSection:toSection:
单元格编辑
editing Property
- setEditing:animated:
重载表视图
- reloadData
- reloadRowsAtIndexPaths:withRowAnimation:
- reloadSections:withRowAnimation:
- reloadSectionIndexTitles
访问的表视图区域
- rectForSection:
- rectForRowAtIndexPath:
- rectForFooterInSection:
- rectForHeaderInSection:
delegate和数据源
// dataSource Property
@property(nonatomic, weak) id< UITableViewDataSource > dataSource;
// delegate Property
@property(nonatomic, weak) id< UITableViewDelegate > delegate;
UITableViewDelegate
UITableViewDataSource
配置表索引
sectionIndexMinimumDisplayRowCount Property
sectionIndexColor Property
sectionIndexBackgroundColor Property
sectionIndexTrackingBackgroundColor Property
管理焦点
remembersLastFocusedIndexPath Property
常量
UITableViewStyle
UITableViewScrollPosition
UITableViewRowAnimation
Section Index Icons
Default Dimension
##通知
UITableViewSelectionDidChangeNotification