UITableView代理方法的调用顺序

当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:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容