美文网首页
iOS tableview系统左滑删除 左滑置顶 自定义左滑事件

iOS tableview系统左滑删除 左滑置顶 自定义左滑事件

作者: 精神薇 | 来源:发表于2019-02-17 21:44 被阅读0次

    iOS tableview系统左滑删除 左滑置顶 自定义左滑事件功能 输入框弹出
    或者

    //tableView自带的左滑删除
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
        
    }
    // 定义编辑样式
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleDelete;
        
    }
    // 进入编辑模式,按下出现的编辑按钮后,进行删除操作
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
           //。。。。。。
            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            
            
        }
    }
    // 修改编辑按钮文字
    - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
        return @"删除";
        
    }
    //iOS11解决UITableView侧滑删除无限拉伸的方法
    - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){
        if (@available(iOS 11.0, *)) {
            UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
                //。。。。。。
                [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
                // 这句很重要,退出编辑模式,隐藏左滑菜单
                [tableView setEditing:NO animated:YES];
                completionHandler(true);
            }];
    
            UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
            // 禁止侧滑无线拉伸
            actions.performsFirstActionWithFullSwipe = NO;
            return actions;
        }else{
            return nil;
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS tableview系统左滑删除 左滑置顶 自定义左滑事件

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