UITableViewDelegate中代理方法的应用场景整理(二)

接上~

管理上下文菜单

- (UITargetedPreview *)tableView:(UITableView *)tableView 
previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration;

参数:

tableView:通知代理这个事件的表视图。

configuration:菜单被展示的配置。

返回:关闭上下文菜单时返回目标视图。


- (UITargetedPreview *)tableView:(UITableView *)tableView 
previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration;

参数:

tableView:通知代理这个事件的表视图。

configuration:菜单被突出显示的配置。

返回:返回一个视图已覆盖创建的表视图的默认预览。


还有几个我还没有使用过的,这里先把官方的解释放到这里,以后遇到了再总结使用场景。

- tableView:willDisplayContextMenuWithConfiguration:animator:
在上下文菜单出现时通知委托。

- tableView:willEndContextMenuInteractionWithConfiguration:animator:
在上下文菜单消失时通知委托。

- tableView:willPerformPreviewActionForMenuWithConfiguration:animator:
当用户通过点击预览触发提交时通知委托。

响应行动作

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView 
leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath;

参数:tableView:包含行的表视图。

返回值:滑动动作显示在该行的前沿;返回nil表示在表格中显示默认设置。而与之配对的就是显示在行的末尾的操作,方法描述如下:

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView 
trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath;

管理表视图突出显示

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

参数解释:发出请求的表视图以及被突出显示的行的索引。

返回:YES表示应该被突出显示,反之不应该。

使用场景介绍:当出现触摸事件的时候,表视图会预料用户可能选择的行,将其突出显示。当处理这些触摸事件的时候,表视图会调用这个方法询问代理给定的单元格是否应该突出显示。在我们想控制当另一个已经被选中或者出现其他的相关标准时,为了使当前的不突出显示,我们可以使用这个方法。这个方法的默认值为YES。


下面的两个是一组,分别是告诉代理指定的行突出显示了以及指定的突出显示的行,突出显示效果移除了。

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

编辑表格行

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

告诉代理表视图将要进入编辑状态。

使用场景:

当用户在一行中滑动的时候,表视图会将editing参数设为YES,表视图进入标记模式,在指定的行中会显示删除按钮,在“滑动删除”模式中,表视图不显示任何插入删除重排序的控制。使得带了可以有机会去让应用的使用者的UI适应编辑模式。当表格退出编辑模式的时候,表视图调用如下tableView:didEndEditingRowAtInexPath:方法。

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

告诉代理表视图离开编辑着模式。


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

要求代理为指定位置的行显示指定的编辑样式。这个方法可以为表格使用自定义的样式,如果委托没有实现这个方法,并且editing属性为YES,单元格使用UITableViewCellEditingStyleDelete样式。


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

更改表视图的指定行的删除确认按钮的默认标题。返回的字符串作为删除确认按钮的标题。默认标题为“Delete”


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

询问delegate当表视图处于编辑模式的时候是否缩进该行的背景。YES代表缩进反之不缩进。默认为YES。


重新排序表格行

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

要求代理返回一个新的索引地址来重定位行的需要的移动。

当在表视图中上下移动特定行时,此方法允许为特定行定制目标行。当拖动的行悬停在另一行上时,目标行向下滑动以在视觉上为重定位留出空间;这是所标识的位置-proposedDestinationIndexPath。


跟踪视图的删除

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

告诉委托特定的行已经被从表中移除。

使用这个方法来检测什么时候单元格从表视图中被移除,而不是监控视图本身来知晓他什么时候出现或消失。


对于HeaderView以及FooterView都有一样的方法:

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

管理表视图焦点

- (BOOL)tableView:(UITableView *)tableView 
canFocusRowAtIndexPath:(NSIndexPath *)indexPath;

询问委托指定位置的单元格是否成为焦点。

- (BOOL)tableView:(UITableView *)tableView 
shouldUpdateFocusInContext:(UITableViewFocusUpdateContext *)context;

询问委托是否允许由上下文指定的焦点更新发生。

- (void)tableView:(UITableView *)tableView 
didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context 
withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator;

告诉委托该上下文指定的焦点更新刚刚发生。

- (NSIndexPath *)indexPathForPreferredFocusedViewInTableView:(UITableView *)tableView;

向委托人请求首选焦点视图的表视图的索引路径。


就此所有的UITAbleViewDelegate中设计到的方法就整理结束了。之后会在我使用到的时候对一些使用心得进行补充。我是通过官方文档进行学习整理的,大家看完之后也可以再去看官方文档加深一下理解。:)

创作不易,随手点个赞呗~

猜你喜欢

转载自blog.csdn.net/qq_40230669/article/details/107832476
今日推荐