Disclosure indicator to specific cell in static TableView in Swift

假如想象 提交于 2019-11-29 15:54:53

Your are working with static cells so cellForRow will not get called. Instead, simply drag connect your cell and set it up, like this

Just check if you want to show disclosure indicator in cellForRowAt indexPath method.

if (wantsToShow){ // Your condition goes here
   cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
}
else{
   cell.accessoryType = .none
}

That's it.

Please use below code in cellForRowTableView code

It will work for you

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 
    if currentUser {
     // Own Account
       cell.accessoryType = .none
       //cell.backgroundColor = UIColor.red
    }else{
     //Guest Account
     cell.accessoryType =.checkmark
    }
}

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
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!