iOSTableView的代理函数

1.必须

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    // 返回tableView的分区数

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    // 返回每个分数数的行数

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 返回tableView中每行的内容

}


2.编辑(删除,插入等)

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 返回是否可以编辑

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 对当前行数设置编辑模式(删除,插入,不可编辑,多选(|))

}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 真正实现编辑的方法,在这个方法里面修改数据源,刷新

}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 修改删除按钮的文本显示

}

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托,表视图将要被编辑时调用(删除、插入,而不是对cell内容进行编辑)

}

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 表视图完成编辑时调用

}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托在编辑模式下是否需要对表视图指定行进行缩进,这个方法可以用来去掉moverow前面的空白

}


3.选择(取消选中:在下一行将要被选中后才能取消上一行的选中)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定行被选中

}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定行将被选中,返回值为NSIndexPath是指返回响应行的索引,即可以点击一行而返回另一行的索引,也可以返回nil

}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托某行被取消选中

}

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定行将被取消选中

}


4.设置高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 返回每一行的高度

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    // 返回每一个sectionheader的高度

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    // 返回每一个sectionfooter的高度

}


5.设置header和footer

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    // 定义每一个sectionheader的名称

}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    // 定义每一个sectionfooter的名称

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

    // 设置分区的header的视图,可以为任何UIView的子类

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

    // 设置分区的footer的视图

}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托将要显示sectionheader的视图

}

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托将要显示sectionfooter的视图

}


6.cell的移动

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 是否可以移动

}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

    // 移动调用的方法,可以在里面设置数据源的一些操作

}

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath*)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath

{

    // 移动的过程中多次调用次方法,返回值是进行移动操作结束后回到的行,如果是当前行,则不论移动到哪一行都会回到当前行

    // 其中sourceIndexPath是要移动的行

    // proposedDestinationIndexPath经过的行

}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定cell已经移出可视范围

}

- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托指定的sectionheader已经移出可视范围

}

- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托指定的sectionfooter已经移出可视范围

}



7.索引

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

    // 返回索引的数组

}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

{

    // 点击索引的时候调用该方法

}


8.cell即将显示

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    // cell将要显示时候调用这个方法,可以在这里面修改cell的一些属性,如颜色

}


9.长按菜单

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 是否显示长按菜单

}

- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender

{

    // 弹出选择菜单时会调用这个方法(复制、黏贴、全选、剪切)

}

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender

{

    // 选择菜单项完成之后调用该方法

}


10.高亮显示

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 选中行是否高亮

}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定行被高亮显示

}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托表视图的指定行不再高亮显示,一般是在点击其他行的时候调用

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值