iOS tableView側滑刪除的第三方控件

(到個人文件中,下載「tableview中cell測滑刪除的第三方控件」),使用方法以下:ide

在tableView中的.m中,設置cell的方法上,事例代碼以下,其中,EaseConversationCell繼承於LYSideslipCellspa

- (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; }

效果圖以下:code

(參考代碼:美業B端-MYBConsultViewController.m)orm

 

其中,這個控件的好處是,能夠監聽到cell側滑時的動做,好比須要在側滑後改變cell的顏色,這個控件就能夠實現到,在LYSideslipCell.m中:監控以下這兩個方法便可:blog

- (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);
}

 

繼承

相關文章
相關標籤/搜索