【问题标题】:iOS 11 Tableview SelectioniOS 11 表格视图选择
【发布时间】:2018-03-25 19:50:36
【问题描述】:

我致力于 tableview 功能,以便在选择 tableview 单元格时,tableview 重新加载并在所选行中显示复选标记。所选行未突出显示,并且不允许选择多行。

在 iOS 11 中,它按预期停止工作。我希望选定的行显示一个复选标记。另外,所选行的背景不应突出显示,并且不允许选择多行。

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
    let clientCell = tableView.dequeueReusableCell(withIdentifier: "clientCell", for: indexPath)
    clientCell.selectionStyle = .none

    if selectedIdxPath == indexPath.row {
        clientCell.accessoryType = UITableViewCellAccessoryType.checkmark
    } else {
        clientCell.accessoryType = UITableViewCellAccessoryType.none
    }
    return clientCell
}

func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
    selectedIdxPath = indexPath.row
    tableView.reloadData()
}

【问题讨论】:

    标签: uitableview ios11 xcode9 swift4


    【解决方案1】:

    请检查您的委托方法:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let clientCell = tableView.dequeueReusableCell(withIdentifier: "clientCell", for: indexPath)
        clientCell.selectionStyle = .none
    
        if selectedIdxPath == indexPath.row {
            clientCell.accessoryType = UITableViewCellAccessoryType.checkmark
        } else {
            clientCell.accessoryType = UITableViewCellAccessoryType.none
        }
        return clientCell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectedIdxPath = indexPath.row
        tableView.reloadData()
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-25
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多