Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda