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

310
Views
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 answers
Answer question

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 Report
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!