iOS之UITableView

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
















  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值