iOS tableView側滑刪除的第三方控制項

來源:互聯網
上載者:User

標籤:mode   consul   wan   option   控制項   normal   tar   efault   default   

(到我的檔案中,下載“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);}

 

 

iOS tableView側滑刪除的第三方控制項

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.