我有一个表格视图,在单元格的轻按位置上显示选中标记。但是在显示单元格之前,如果单元格满足特定条件,则应显示带有复选标记的附件
在我的cellforRow代码中
guard let cell = tableView.dequeueReusableCell(withIdentifier: myConstants.detailCell, for: indexPath) as? DetailTableViewCell else {
return UITableViewCell()
}
if let checkIndex = selectedIndex, checkIndex == indexPath.row {
cell.accessoryType = UITableViewCell.AccessoryType.checkmark //THis did not work so added next line
cell.setSelected(true, animated: false) // This also did not work
cell.configureCell(with: infoDataSource, at: indexPath.row, isChecked: true) //Updated my configure cell method to show accessory type like below..but none of them works
} else {
cell.accessoryType = UITableViewCell.AccessoryType.none
cell.setSelected(false, animated: false)
cell.configureCell(with: infoDataSource, at: indexPath.row)
}
首次显示tableview时,我的所有单元格都未显示选中标记。当我点击单元格时它会显示出来,但是如果满足某些条件,也会出现复选标记。.下面是我的DetailTableViewCell的配置单元格方法
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
self.accessoryType = selected ? .checkmark : .none
// Configure the view for the selected state
}
func configureCell(with data: NotesListModel?, at index: Int, isChecked: Bool = false) {
guard let cellData = data?.noteName(at: index) else {
return
}
self.textLabel?.text = cellData
self.textLabel?.numberOfLines = 0
self.accessoryType = isChecked ? .checkmark : .none
}
我也在这里尝试设置self.accessoryType,但是在显示tableview时也不会显示。我在这里想念什么?请指教