您的位置:首页 > 产品设计 > UI/UE

iOS之UITableView

2015-09-24 14:16 447 查看
UITableViewDelegate协议方法

返回每一行单元格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

返回分区区头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

返回分区区角的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

返回分区区头的自定义View(可以使用重用机制)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

返回分区区脚的自定义View(可以使用重用机制)
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

单元格右侧附件按钮点击时执行的方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

将要选中单元格的时候执行的方法
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

不选中单元格执行的方法
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath

选中单元格时候执行的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

取消选中单元格时候执行的方法
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

设置每一个单元格的编辑风格
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert

设置按钮的标题
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

设置单元格是否需要缩排
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath

单元格即将编辑时执行的方法
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

单元格完成编辑时候执行的方法
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath

单元格在移动过程中执行的方法
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath
*)proposedDestinationIndexPath

是否显示菜单的复制粘贴
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewDataSource协议方法

必须实现:
每个分区有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

每个单元格的内容(单元格有重用机制,并且可以自定义)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

非必须实现:
有多少分区(默认为1)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

分区区头标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

分区区脚标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

设置单元格是否可以编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

设置单元格是否可以移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

设置表格右侧的索引数组
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

设置表格的索引和分区的对应关系
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

提交单元格编辑状态的时候执行的方法(即添加.删除按钮)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath

单元格移动的时候执行的方法(从初始位置到目标位置)
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath
*)destinationIndexPath
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: