1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      iOS多選刪除功能附tableViewTips及單選刪除

      一、前言

      成都創(chuàng)新互聯(lián)公司長期為1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為五指山企業(yè)提供專業(yè)的做網(wǎng)站、網(wǎng)站制作五指山網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

      這次分享并記錄一下tableView的多選刪除,并額外記錄一下單選刪除及tableView的設(shè)置小技巧。

      二、想要實現(xiàn)的效果圖如下:

      1、先上原圖

      iOS 多選刪除功能附tableViewTips及單選刪除

      2、然后編輯圖如下:

      iOS 多選刪除功能附tableViewTips及單選刪除

      3、編輯步驟:

      點擊右上角按鈕編輯,界面呈現(xiàn)編輯狀態(tài)底部刪除按鈕彈出

      選擇刪除cell項,點擊右下角刪除可刪除

      點擊右上角,退出編輯狀態(tài),底部刪除按鈕退出界面

      三、多選刪除核心代碼

      1、設(shè)置允許tableView編輯狀態(tài)下允許多選

      _mainTableView.allowsMultipleSelectionDuringEditing = YES;

      2、將cell設(shè)置為可選擇的風(fēng)格(下面代碼是在自定義Cell內(nèi)部)

      self.selectionStyle = UITableViewCellSelectionStyleDefault;

      說明:因為自認(rèn)為系統(tǒng)的選中狀態(tài)很難看,所以在cell的基類里已經(jīng)把 selectionStyle 設(shè)置為None,但是想要多選必須將其打開,大家切記。

      3、不喜歡系統(tǒng)的選中狀態(tài),可更改選中狀態(tài)的背景(下面也是在自定義cell內(nèi)部)

       UIView *view = [[UIView alloc] init];
       view.backgroundColor = UIColorFromRGB(0xF6F6F6);
       self.selectedBackgroundView = view;

      4、右上角點擊事件

       [self.viewModel.rightViewModel.clickSubject subscribeNext:^(id x) {
          @strongify(self);
          if (self.mainTableView.editing) {
            self.viewModel.rightViewModel.title = @"編輯";
            [UIView animateWithDuration:0.5 animations:^{
              [self.mainTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
                @strongify(self);
                make.edges.equalTo(self);
              }];
            }];
          } else {
            self.viewModel.rightViewModel.title = @"確定";
            [UIView animateWithDuration:0.5 animations:^{
              [self.mainTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
                @strongify(self);
                make.left.right.top.equalTo(self);
                make.bottom.equalTo(-50);
              }];
            }];
          }
          [self.mainTableView setEditing:!self.mainTableView.editing animated:YES];
        }];

      5、右下角刪除事件

       [[[self.deleteBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
           @strongify(self);
          NSMutableArray *deleteArray = [NSMutableArray array];
          for (NSIndexPath *indexPath in self.mainTableView.indexPathsForSelectedRows) {
            [deleteArray addObject:self.viewModel.dataArray[indexPath.row]];
          }
          NSMutableArray *currentArray = self.viewModel.dataArray;
          [currentArray removeObjectsInArray:deleteArray];
          self.viewModel.dataArray = currentArray;
          [self.mainTableView deleteRowsAtIndexPaths:self.mainTableView.indexPathsForSelectedRows withRowAnimation:UITableViewRowAnimationLeft];//刪除對應(yīng)數(shù)據(jù)的cell
          dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
          dispatch_after(delayTime, dispatch_get_main_queue(), ^{
            @strongify(self);
            [self.mainTableView reloadData];
          });
        }];

      四、單個刪除(分為系統(tǒng)左滑,和點擊cell上刪除按鈕兩種)

      1、系統(tǒng)左滑

      #pragma mark - delete
      - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleDelete;
      }
      - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
        return @"刪除此經(jīng)驗";
      }
      - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        [self.viewModel.deleteCommand execute:indexPath];
      }

      說明:刪除操作數(shù)據(jù)及UI刷新和多選是一致的,就不上代碼了,這里只需注意左滑需要遵循的系統(tǒng)代理就行。

      2、點擊Cell刪除

      與系統(tǒng)左滑刪除的不同僅僅是手動觸發(fā)刪除事件而已。

        [[[self.deleteBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
          [viewModel.deleteCommand execute:nil];
        }];

      單個刪除的操作數(shù)據(jù)和UI刷新也上下代碼吧!(雖然有些重復(fù)o(╯□╰)o)

       [[self.viewModel.deleteSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSIndexPath *indexPath) {
          @strongify(self);
          if (self.viewModel.dataArray.count > indexPath.row) {
            [self.viewModel.dataArray removeObjectAtIndex:indexPath.row]; //刪除數(shù)組里的數(shù)據(jù)
            [self.mainTableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];//刪除對應(yīng)數(shù)據(jù)的cell
            dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
            dispatch_after(delayTime, dispatch_get_main_queue(), ^{
               @strongify(self);
               [self.mainTableView reloadData];
            });
          }
        }];

      五、tableView的一些Tips(不常用的,或沒注意的)

      1、設(shè)置tableView可不可以選中(防止cell重復(fù)點擊也可以利用這條特性)

      self.tableView.allowsSelection = NO;

      2、允許tableview多選

      self.tableView.allowsMultipleSelection = YES;

      3、編輯模式下是否可以選中

      self.tableView.allowsSelectionDuringEditing = NO;

      4、編輯模式下是否可以多選

      self.tableView.allowsMultipleSelectionDuringEditing = YES;

      5、獲取被選中的所有行

      [self.tableView indexPathsForSelectedRows]

      6、獲取當(dāng)前可見的行

      [self.tableView indexPathsForVisibleRows];

      7、 改變UITableViewCell選中時背景色

      cell.selectedBackgroundView.backgroundColor

      8、自定義UITableViewCell選中時背景

      cell.selectedBackgroundView

      9、自定義UITableViewCell選中時系統(tǒng)label字體顏色

      cell.textLabel.highlightedTextColor

      10、設(shè)置tableViewCell間的分割線的顏色

      [theTableView setSeparatorColor:[UIColor xxxx ]];

      11、pop返回table時,cell自動取消選中狀態(tài)(在viewWillAppear中添加如下代碼)

      [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];

      12、點擊后,過段時間cell自動取消選中

       - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        //消除cell選擇痕跡
        [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
      }
      - (void)deselect {
        [self.tableview deselectRowAtIndexPath:[self.tableview indexPathForSelectedRow] animated:YES];
      }

      以上所述是小編給大家介紹的AniOS 多選刪除功能附tableViewTips及單選刪除,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!


      網(wǎng)頁標(biāo)題:iOS多選刪除功能附tableViewTips及單選刪除
      瀏覽路徑:http://www.ef60e0e.cn/article/gopoid.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        工布江达县| 儋州市| 大足县| 同仁县| 金秀| 通城县| 红桥区| 万宁市| 石棉县| 岚皋县| 三明市| 故城县| 清远市| 临泽县| 易门县| 四川省| 平昌县| 布尔津县| 湟源县| 开鲁县| 柳林县| 江油市| 化隆| 昌吉市| 会昌县| 七台河市| 盖州市| 额济纳旗| 南雄市| 元谋县| 寻乌县| 广南县| 景谷| 额尔古纳市| 崇文区| 新建县| 巢湖市| 谢通门县| 遂昌县| 河曲县| 广汉市|