【问题标题】:Disable UITableViewCell edit mode with rxswift使用 rxswift 禁用 UITableViewCell 编辑模式
【发布时间】:2016-06-23 07:53:29
【问题描述】:

我使用 rxswift 将我的数据源绑定到 tableview,但默认情况下,当我这样做时,单元格是可编辑的,我该如何禁用该功能?

这是我得到的tableview示例:

【问题讨论】:

  • 嘿@Petros,你是如何使用 RxSwift 禁用编辑模式的?
  • @Abhishek tableView.rx_setDelegate(self)func tableView(tableView: UITableView, editingStyleForRowAtIndexPath: NSIndexPath) -> UITableViewCellEditingStyle { return UITableViewCellEditingStyle.None }

标签: ios swift2 rx-swift


【解决方案1】:

你在使用 RxDataSources 吗?您可以按如下方式配置您的数据源

dataSource.canEditRowAtIndexPath = {dataSource, indexPath in false }

【讨论】:

    【解决方案2】:

    我不知道我是否理解你的问题。但是,如果您只是想禁用单元格上的编辑模式,请添加以下代码:

    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return false
    }
    

    【讨论】:

      【解决方案3】:

      这里是代码示例

             viewModel
                  .fetchMockServicesDataSource()
                  .asObservable()
                  .bindTo(mockServiceTableView.rx_itemsWithCellIdentifier("mockCell", cellType: MockTableViewCell.self)) { row, element, cell in
                      cell.updateCell(element)
                  }
                  .addDisposableTo(disposeBag)
      

      但无论如何我找到了可行的解决方案 我需要添加这些部分

      mockServiceTableView.rx_setDelegate(self)
      
      
      func tableView(tableView: UITableView, editingStyleForRowAtIndexPath: NSIndexPath) -> UITableViewCellEditingStyle {
          return UITableViewCellEditingStyle.None
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多