ios 侧滑删除, 一直往左滑的话删除按钮会随着cell一直往右扩展,拉到尽头就执行删除方法

参考链接:UITableView侧滑删除在iOS 11.2上的新特性 | iOS开发 - CocoaChina CocoaChina_让移动开发更简单

UITableView侧滑删除问题:

    在11.0系统之前cell左滑时话删除按钮不会跟着cell一直扩展

    在11.0系统之后cell左滑时话删除按钮会跟着cell一直扩展, 左滑到头时会执行相应方法

期望结果:

    在11.0系统之后的效果像在11.0系统之前的效果一样,左滑到头时不自动执行相应的方法

解决办法:

重写下面的方法: 这个方法11.0之后才有效

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){

    UIContextualAction *deleteAction = [UIContextualAction

                                       contextualActionWithStyle:UIContextualActionStyleDestructive

                                        title:@"删除"

                                        handler:^(UIContextualAction * _Nonnull action,

                                                  __kindof UIView * _Nonnull sourceView,

                                                  void (^ _Nonnull completionHandler)(BOOL))

                                        {

                                            [tableView setEditing:NO animated:YES];  // 这句很重要,退出编辑模式,隐藏左滑菜单

                                            [self.arr removeObjectAtIndex:indexPath.row];

                                            [_table deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];

                                            [_table reloadData];

                                            completionHandler(true);

                                        }];

    UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];

    actions.performsFirstActionWithFullSwipe = NO;

    return actions;

你可能感兴趣的:(ios 侧滑删除, 一直往左滑的话删除按钮会随着cell一直往右扩展,拉到尽头就执行删除方法)