iosswiftuitableviewaccessoryview

Custom Accessory Button in UITableViewCell


I am trying to add a custom button in the Accessory View for a UITableViewCell.

I have added the following code:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {      
       // ....     
       let button = UIButton(type: .custom)
       button.setImage(UIImage(named: "arrow-right-light.png")?.maskWithColor(color: .white), for: .normal)
       button.addTarget(self, action: #selector(buttonTest), for: .touchUpInside)
       button.tag = indexPath.row
       cell.accessoryView = button
       // ...

However, I don't see the button show up on in the Accessory View.


Solution

  • I can think of two possible reasons: