iOS tableView侧滑删除的第三方控件

(到我的文件中,下载“tableview中cell测滑删除的第三方控件”),使用方法如下:

在tableView中的.m中,设置cell的方法上,事例代码如下,其中,EaseConversationCell继承于LYSideslipCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = [EaseConversationCell cellIdentifierWithModel:nil];
    EaseConversationCell *cell = (EaseConversationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[EaseConversationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.consultModel = self.dataArray[indexPath.section];
  //添加侧滑之后的按钮
    KDButton *deleteBtn = [cell rowActionWithStyle:LYSideslipCellActionStyleNormal title:nil];
    deleteBtn.index = indexPath.row;
    deleteBtn.section = indexPath.section;
    deleteBtn.backgroundColor =[UIColor redColor];
    [deleteBtn setBackgroundImage:kUIImage(@"delete") forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cell setRightButtons:@[deleteBtn]];//可以传多个
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

效果图如下:

(参考代码:美业B端-MYBConsultViewController.m)

 

其中,这个控件的好处是,可以监听到cell侧滑时的动作,比如需要在侧滑后改变cell的颜色,这个控件就可以实现到,在LYSideslipCell.m中:监控如下这两个方法即可:

- (void)hiddenSideslipButton {
    //侧滑恢复后的操作
    if (_containLeftConstraint.constant == 0) return;
    
    [self closeAllOperation];
    _containLeftConstraint.constant = _sideslipLeftConstraint.constant = 0;
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self openAllOperation];
    }];
    _backGroundView.backgroundColor = UIColorFromRGB(0xF7F7F7);
    _backGroundView.frame = CGRectMake(10, 0, kScreenW - 20, 85);
}

- (void)showSideslipButton {
   //侧滑后的操作
    [self closeAllOperation];
    _containLeftConstraint.constant = _sideslipLeftConstraint.constant = -CGRectGetWidth(_sideslipView.frame);
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        for (LYSideslipCell *cell in self.tableView.visibleCells)
            if ([cell isKindOfClass:LYSideslipCell.class]) {
                cell.userInteractionEnabled = YES;
            }
    }];
    _backGroundView.backgroundColor = UIColorFromRGB(0xE7F8FF);
    _backGroundView.frame = CGRectMake(10, 0, kScreenW - 10, 85);
}

 

 

 
 
 
 
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值