关于UITableView委托方法的功能(by atany)

UITableViewDataSource

1)tableView:cellForRowAtIndexPath:

申请一个cell插入到表视图特定的位置,cell生成访问到的方法。

2)numberOfSectionsInTableView:

返回表视图的分区数。

3)tableView:numberOfRowsInSection:

返回表视图中每个分区的行数。

4)sectionIndexTitlesForTableView:

返回分区索引的名称,使用此方法会在表视图右侧创建一个索引栏,通过点击索引可以快速跳转到指定分区。

5)tableView:sectionForSectionIndexTitle:atIndex:

点击索引栏会调用此事件,通过点击的标题与索引返回分区的索引。简单来说,就是设定点击右侧索引栏会跳转到的分区,如return 0,那么无论点击什么,都会跳转到分区0。

6)tableView:titleForHeaderInSection:

定义每一个分区头的名称。

7)tableView:titleForFooterInSection:

定义每一个分区尾的名称。

8)tableView:commitEditingStyle:forRowAtIndexPath:

要求数据源提交插入或者删除指定行的事件。即每次删除或者插入完成后都会响应该方法,commitEditingStyle参数标识此次操作是UITableViewCellEditingStyleInsert(插入)

or UITableViewCellEditingStyleDelete(删除)。

9)tableView:canEditRowAtIndexPath:

使得指定行为可编辑状态。

10)tableView:canMoveRowAtIndexPath:

使得指定行成可移动状态,如果指定为NO,则该行不会出现可拖动图标。

11)tableView:moveRowAtIndexPath:toIndexPath:

移动行之后调用的方法,可以在里面设置表视图数据list的一些操作。

UITableViewDelegate

1)tableView:heightForRowAtIndexPath:

返回行的高度。

2)tableView:willDisplayCell:forRowAtIndexPath:

在Cell将要显示时调用此方法,可以在这里修改重用的Cell的一些属性,例如颜色。

3)tableView:willSelectRowAtIndexPath:

通知委托指定行被将要选中,返回值为NSIndexPath是指返回响应行的索引,即可以点击一行而返回另一行索引,如果不想点击事件响应则返回nil。

4)tableView:didSelectRowAtIndexPath:

通知委托指定行被选中。

5)tableView:willDeselectRowAtIndexPath:

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

6)tableView:didDeselectRowAtIndexPath:

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

关于3)到6)的执行顺序:

willSelectRowAtIndexPath 当前行为:0

didSelectRowAtIndexPath 当前行为:0

willSelectRowAtIndexPath 当前行为:1

willDeselectRowAtIndexPath 当前行为:0

didDeselectRowAtIndexPath 当前行为:0

didSelectRowAtIndexPath 当前行为:1

注:在下一行将要选中后才取消上一行的选中。

7)tableView:viewForHeaderInSection:

设置分区的header的视图,可以为它添加图片或者其他控件(UIView的子类)

8)tableView:viewForFooterInSection:

设置分区footer的视图,可以为它添加图片或者其他控件(UIView的子类)

9)tableView:heightForHeaderInSection:

设置分区header的高度。

10)tableView:heightForFooterInSection:

设置分区footer的高度

11)tableView:willDisplayHeaderView:forSection:

通知委托将要显示分区header的视图

12)tableView:willDisplayFooterView:forSection:

通知委托将要显示分区footer的视图

13)tableView:willBeginEditingRowAtIndexPath:

通知委托,表视图将要被编辑(删除或者插入,而是不是编辑cell文字哦)

14)tableView:didEndEditingRowAtIndexPath:

表视图完成编辑。

15)tableView:editingStyleForRowAtIndexPath:

对当前行设置编辑模式,删除、插入或者不可编辑。

typedef enum {

//不可编辑

UITableViewCellEditingStyleNone,

//删除

UITableViewCellEditingStyleDelete,

//插入

UITableViewCellEditingStyleInsert

}UITableViewCellEditingStyle;

16)tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:

在删除模式启动下,改变每行删除按钮的文字(默认为“Delete”)

17)tableView:shouldIndentWhileEditingRowAtIndexPath:

通知委托在编辑模式下是否需要对表视图指定行进行缩进,NO为关闭缩进,这个方法可以用来去掉move时row前面的空白。

18)tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

移动行的过程中会多次调用此方法,返回值代表进行移动操作后回到的行,如果设置为当前行,则不论怎么移动都会回到当前行。

19)tableView:didEndDisplayingCell:forRowAtIndexPath:

通知委托指定的cell已经移出表视图,即拖动的时候移出视图的cell。

20)tableView:didEndDisplayingHeaderView:forSection:

通知委托指定的分区头已经移出表视图。

21)tableView:didEndDisplayingFooterView:forSection:

通知委托指定的分区尾已经移出视图

22)tableView:shouldShowMenuForRowAtIndexPath:

通知委托是否在指定行显示菜单,返回值为YES时,长按显示菜单。

23)tableView:canPerformAction:forRowAtIndexPath:withSender:

弹出选择菜单时会调用此方法(复制、粘贴、全选、剪切)

24)tableView:performAction:forRowAtIndexPath:withSender:

选择菜单项完成之后调用此方法。

25)tableView:shouldHighlightRowAtIndexPath:

通知委托是否开启点击高亮显示,YES为显示。

26)tableView:didHighlightRowAtIndexPath:

通知委托表示图的指定行被高亮显示。

27)tableView:didUnhighlightRowAtIndexPath:

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

(转载自网络by atany)

你可能感兴趣的:(关于UITableView委托方法的功能(by atany))