是什么?
- 操作按钮的样式.
-
UIContextualActionStyle 为: Normal 时
- 它是灰色背景的按钮.
- 滑动到
cell
的1/2位置时, 就完成了"完全滑动".
-
UIContextualActionStyle 为: Destructive 时
- 它是红色背景的按钮.
- 能够滑动整个
cell
. - 为Y时, 不写删除代码,会删除当前所选的cell.
-
"完全滑动":多个按钮,因滑动而成为1个按钮。
什么特点?
-
UIContextualActionStyle 为: Destructive
且completionHandler 为 Y
, 在完全没有写"删除cell的代码"的情况下,可以直接删除选中的cell
UIContextualAction * deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { NSLog(@"删除...."); //执行操作 completionHandler(YES); }];

UIContextualActionStyle
和completionHandler
结合应用时的区别?
-
UIContextualActionStyle 为:
Destructive
- 红色背景的按钮。-
completionHandler 为 Y
,出现的情况: (参照上面,"什么特点 ?") -
completionHandler 为 N
,出现的情况:-
"不写删除代码的情况下", 不会删除当前
cell
-
"不写删除代码的情况下", 不会删除当前
-
completionHandler 为 默认时
,出现的情况:- 完全滑动时,能够暂停。
- 暂停后,点击"删除"按钮,会执行"删除按钮的代码块",并且会执行,其他按钮的代码块.如:"编辑"按钮的代码块.
-
-
UIContextualActionStyle 为:
Normal
- 灰色背景的按钮。-
completionHandler为Y或N时
,出现的情况:-
"不写删除代码的情况下",不会删除当前的
cell
-
"不写删除代码的情况下",不会删除当前的
-
completionHandler 为 默认时
,出现的情况:- 会暂停, 会执行"删除按钮的代码块".
- 同时也会执行其他按钮的代码块. 如: "编辑"按钮的代码块.
-
问题:
- 为什么会出现"延迟删除"的情况呢?
-
completionHandler(NO);
"不完成处理"的意思. 所以点击"删除",不会删除选中的cell。
UIContextualActionStyleDestructi
, 如果完成处理,就是会删除当前选中的cell
. - 可是代码块里面,有写"删除选中行的代码"。所以点击其他cell的时候,会删除cell。( 延迟删除)
-
completionHandler(YES);
立刻处理。就是马上删除当前选中cell
.
-
UIContextualAction * deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSLog(@"删除....");
if (self.wineData.count > indexPath.row) {
[self.wineData removeObjectAtIndex:indexPath.row];
//局部刷新
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
//执行操作
completionHandler(NO);
}];
也可以看看
UISwipeActionsConfiguration - 表格行滑动后的操作配置
UIContextualAction - 用户滑动表格行后,执行操作的事件
UIContextualActionHandler - 执行操作的代码块
来自于哪里?
- iOS-MJ-UI基础-大神班/day-10/左滑出现多个按钮
网友评论