2017-10-13 67 views
0

我使用了tableview功能,因此当选择tableview单元格时,tableview将重新加载并在选定行中显示复选标记。所选行未突出显示,并且不允许选择多行。iOS 11 Tableview Selection

对于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() 
} 

回答

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