Vitalii Zaitcev
1 min readDec 23, 2020

--

Hi Mike! Good question.

First of all, you don't need to communicate with coordinator from UITableViewCell, UICollectionViewCell, or any other subview in the hierarchy. Personally, I follow a simple rule here: View never should know about its parent. You might ask why? Well, because it helps you to build reusable views, keep code clean, and follow the single responsibility principle.

Answering your question, you have a couple of options here:

- Use closures to expose actions you need (I'd prefer this for UITableViewCell/UICollectionViewCell) or use delegate pattern. I described steps of how to do that in my other article https://somevitalyz123.medium.com/another-way-to-handle-subviews-actions-and-states-using-enum-d3c26091096a

- Assign action directly to UIControl via addTarget. Don't forget to assign "indexPath.row" of the cell to the tag of the button so you can track from which cell the particular button was tapped.

Implementing one of these approaches you would be able to notify ViewController about some action, and ViewController can notify coordinator to do anything you need.

Hope my explanation helped you 🙏 Let me know if something wasn't clear.

--

--

Vitalii Zaitcev
Vitalii Zaitcev

No responses yet