How to remove ui view after cell tap?

Viewed 82

I have a custom xib table view cell that has a green uiview on it. The uiview acts as a new message indicator - whenever a message comes in, the green view is displayed. When a user taps the cell, I want to set the view to hidden.

My only question is; how would I go about hiding the view just on that specific table view cell and not all table view cells?

1 Answers

You can get the reference of the cell that should hide the green view as follow:

guard let cell = tableView.cellForRow(at: IndexPath(row: yourRowIndex, section: yourSectionIndex)) as? YourCustomTableViewCell else { return }
    cell.greenView?.isHidden = true

and hide the green view with the isHidden property set to true. Of course you have to provide the right IndexPath for your specific cell, for instance if you want to hide the green view of the third cell at the second section your IndexPath would be IndexPath(row: 2, section: 1) and then cast the cell to your specific cell type.

Related