美文网首页iOS效果
iOS 11 取消TableView长滑删除

iOS 11 取消TableView长滑删除

作者: 屈涯 | 来源:发表于2018-02-07 15:22 被阅读410次
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
//定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NSLocalizedString(@"Delete", @"");
}

//设置进入编辑状态时,Cell不会缩进
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

//点击删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //在这里实现删除操作
        NoticeListModel *listModel = self.dataArray[indexPath.row];
//        [self.managerDelegate didSelectViewManager:indexPath tableView:tableView model:listModel idfine:@"删除公告"];
        [self.dataArray  removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }
}

-(UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (@available(iOS 11.0, *)) {
        UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        }];
        UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
        config.performsFirstActionWithFullSwipe = NO;
        return config;
    }
    return nil;
}

相关文章

网友评论

  • cloverApp:deleteAction 的block块里要加上
    [tableView setEditing:NO animated:YES];
    completionHandler(true);
    不然点击“删除”没有反应(iOS 11)
  • tp夕阳武士:你这方法没有能够取消长滑删除啊
    tp夕阳武士:@苏_沫 嗯,是我写少了一句
    屈涯:我自己实际用是好用的. 你没有删除掉, 你可以把你代码粘出来. 看看是哪里写的不对.

本文标题:iOS 11 取消TableView长滑删除

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