Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to bind UIButton action in UITableViewCell in MVVM

I have the following MVVM architecture. It is not something special, just for better understanding.

enter image description here

What is the main question is:

How do I need to bind UIButton action to make some reaction in UIViewController.

I try to do it the following way:

1) First of all, I add the property as a closure for ViewModel:

var cellButtonActionCallback: (() -> Void)?

2) I add the same property for CellViewModel:

var buttonCallback: (() -> Void)?

3) When I setup CellViewModel do:

cellViewModel.buttonCallback = cellButtonActionCallback

4) And finally add target for UIButton, and selector buttonAction calls buttonCallback as well:

button.bind { cellViewModel.buttonAction() }

Looks like closure which I define on UITableViewController goes through all viewModels which is not a good idea in my way.

Actually, this approach works fine, but I don't like it.

What is the best way to make the same thing?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!