美文网首页
ios 侧滑删除, 一直往左滑的话删除按钮会随着cell一直往右

ios 侧滑删除, 一直往左滑的话删除按钮会随着cell一直往右

作者: FM_0138 | 来源:发表于2018-06-14 13:53 被阅读0次

    参考链接: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一直往右

          本文链接:https://www.haomeiwen.com/subject/vgcyeftx.html