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

302
Vistas
Mostrar indicador de actividad con RxSwift y MVVM

Tengo una aplicación con arquitectura en capas en la que obtengo una variedad de objetos en ViewModel y los vinculo con tableview en ViewController. El siguiente es mi código: ViewModel:

 func getManufacturerList() -> Single<[ManufacturerItem]> { return self.fetchManufacturerInteractor.getManufacturerList() .map { $0.map { ManufacturerItem( manufacturerName: $0.manufacturerName, manufacturerID: $0.manufacturerID) } } }

La función anterior recibe una matriz de objetos de alguna otra capa que nuevamente la obtiene de NetworkLayer.
Controlador de vista:

 private func setUpViewBinding() { manufacturerViewModel.getManufacturerList() .asObservable() .bind(to: tableView.rx.items(cellIdentifier: LanguageSelectionTableViewCell.Identifier, cellType: LanguageSelectionTableViewCell.self)) { row, manufacturer, cell in cell.textLabel?.text = manufacturer.manufacturerName cell.textLabel?.font = AppFonts.appBoldFont(size: 16).value cell.accessibilityIdentifier = "rowLanguage\(row+1)" cell.textLabel?.accessibilityIdentifier = tblCellLabelAccessibilityIdentifier }.disposed(by: self.disposeBag) }

Ahora, ¿dónde debo agregar el código para mostrar/ocultar el indicador de actividad?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

ViewModel debe manejar mostrar u ocultar IndicatorView (si hay una sola vista de carga) porque su vista debe ser tonta, use BehaviorRelay en lugar de variable (la variable está obsoleta)

en vistaModelo

 // create a subject and set the starter state, every time your viewModel // needs to show or hide a loading, just send an event let showLoading = BehaviorRelay<Bool>(value: true) // your async function func getManufacturerList() -> Observable { // notify subscriber to show the indicator view showLoading.accept(true) // do some works // notify subscribers to hide the indicator view showLoading.accept(false) }

y en tu controlador de vista

 // bind your indicator view to that subject and wait for events showLoading.asObservable().observeOn(MainScheduler.instance).bind(to: indicatorView.rx.isHidden).disposed(by: disposeBag)
over 4 years ago · Santiago Trujillo Denunciar
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