[英]How can I get iOS to show a delete button on a tableView, but not allow a full swipe from the right to delete
A full swipe from the right to delete from a tableView is too dangerous for my app, as my users are reporting accidentally losing data.对于我的应用程序来说,从右侧完全滑动以从 tableView 中删除太危险了,因为我的用户报告意外丢失了数据。
I COULD add an "are you sure?"我可以添加一个“你确定吗?” prompt, but instead I'd like to allow the delete button to appear, but disable the full swipe behaviour.
提示,但我希望允许出现删除按钮,但禁用完全滑动行为。
How can I do that?我怎样才能做到这一点?
Do this by replacing the usual delete button behaviour with your own copy, with performsFirstActionWithFullSwipe set to FALSE通过用您自己的副本替换通常的删除按钮行为来做到这一点,将 performFirstActionWithFullSwipe 设置为 FALSE
- (UISwipeActionsConfiguration *) tableView:(UITableView *)tableView
trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
//optional- returns previous behaviour when table is in edit mode
if (tableView.editing ) {
return nil;
}
UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
// call your existing delete code
[self tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath ];
}];
UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
config.performsFirstActionWithFullSwipe=FALSE; // this is why we are replacing the delete button!
return config;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.