Disclosure indicator to specific cell in static TableView in Swift

前端 未结 4 368
暖寄归人
暖寄归人 2020-12-21 11:42

I created a static TableView and I would like to add or remove a disclosure indicator depending if we are consulting our own account or a guest account.

This is what

4条回答
  •  别那么骄傲
    2020-12-21 12:03

    To add accessory on a specific static cell, I used tableView, cellForRowAt but i couldn't access a reference to UITableViewCell.

    Then i found super.tableView(tableView, cellForRowAt: indexPath)

    So here is my code: Assuming you know the specific indexpath you want:

        var indexPathSort = IndexPath(item: 0, section: 0)
        var indexPathPrice = IndexPath(item: 0, section: 1)
    
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                let cell = super.tableView(tableView, cellForRowAt: indexPath)
                if indexPath == indexPathSort || indexPath == indexPathPrice {
    
                    cell.accessoryType = .checkmark
                }
                return cell
            }
    

提交回复
热议问题