oc基础

UITableView代理方法的调用顺序

2017-02-07  本文已影响458人  权宜平和

当tableview加载的时候,会调用UITableView的UITableViewDelegate和UITableViewDataSource里面对应的方法:

首先:有三轮的调用下面的方法(声明:实现这些方法才会去调用)

第一轮:

numberOfSectionsInTableView: (调用一次)

tableView:heightForHeaderInSection: (调用两次)

tableView:heightForFooterInSection: (调用两次)

tableView:numberOfRowsInSection: (调用一次)

tableView:heightForRowAtIndexPath: (调用次数和这组的行数一样)

以上是一组cell的调用结果,如果有多组,会重复上面的步骤

第二轮和第三轮的调用结果和第一轮一样

紧接着:会调用以下方法(声明:实现这些方法才会去调用)

tableView:cellForRowAtIndexPath: (调用一次)

tableView:heightForRowAtIndexPath: (调用一次)

tableView:accessoryTypeForRowWithIndexPath:(调用一次)

tableView:canEditRowAtIndexPath:(调用一次)

tableView:willDisplayCell:forRowAtIndexPath:(调用一次)

以上这几个方法,会轮循调用多次,调用的次数和和当前tableview里面可见的cell个数一样

tableView:viewForHeaderInSection:

tableView:titleForHeaderInSection:

tableView:willDisplayHeaderView:forSection:

tableView:viewForFooterInSection:

tableView:titleForFooterInSection:

tableView:willDisplayFooterView:forSection:

以上这几个方法,会轮循调用多次,调用的次数和和当前tableview里面可见的header和footer个数一样

当cell有附加按钮(就是左滑出来的按钮),且cell是可编辑的:会调用以下方法(声明:实现这些方法才会去调用)

tableView:editingStyleForRowAtIndexPath:

tableView:canEditRowAtIndexPath:

tableView:editingStyleForRowAtIndexPath:

tableView:canEditRowAtIndexPath:

tableView:willBeginEditingRowAtIndexPath:

tableView:accessoryTypeForRowWithIndexPath:

tableView:canEditRowAtIndexPath:

tableView:editingStyleForRowAtIndexPath:

tableView:canMoveRowAtIndexPath:

tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:

当点击cell有附加按钮(就是左滑出来的按钮)时:会调用以下方法(声明:实现这些方法才会去调用)

tableView:commitEditingStyle:forRowAtIndexPath:

当cell有附加按钮(就是左滑出来的按钮)消失的时候:会调用以下方法(声明:实现这些方法才会去调用)

tableView:didEndEditingRowAtIndexPath:

tableView:accessoryTypeForRowWithIndexPath:

tableView:canEditRowAtIndexPath:

tableView:didEndEditingRowAtIndexPath:

当首次点击cell时(tableview第一次显示的时候):会调用一下方法(声明:实现这些方法才会去调用)

tableView:shouldHighlightRowAtIndexPath:

tableView:didHighlightRowAtIndexPath:

tableView:didUnhighlightRowAtIndexPath:

tableView:willSelectRowAtIndexPath:

tableView:didSelectRowAtIndexPath:

当再次单击不同于当前的cell时:会调用以下方法(声明:实现这些方法才会去调用)

tableView:shouldHighlightRowAtIndexPath:

tableView:didHighlightRowAtIndexPath:

tableView:didUnhighlightRowAtIndexPath:

tableView:willSelectRowAtIndexPath:

tableView:willDeselectRowAtIndexPath:

tableView:willDeselectRowAtIndexPath:

tableView:didDeselectRowAtIndexPath:

tableView:didSelectRowAtIndexPath:

当长按cell并离开时:会调用以下方法(声明:实现这些方法才会去调用)

tableView:shouldHighlightRowAtIndexPath:

tableView:didHighlightRowAtIndexPath:

tableView:shouldShowMenuForRowAtIndexPath:

tableView:canPerformAction:forRowAtIndexPath:withSender: (会调用很多次)

tableView:didUnhighlightRowAtIndexPath:

上一篇下一篇

猜你喜欢

热点阅读