0

on my project I use RxSwift and Action to handle refresh indicator, but I got issues when run this code. Refresh control not showing, when I debug subscribe work properly but not showing refreshControl. It will be different when I set self.refreshControl?.beginRefreshing() on outside if (executing == true) { block

self.viewModel.transactionHistoryNetworkRequestAction?.executing
        .subscribeOn(MainScheduler.instance)
        .subscribe(onNext: { (executing) in
            if (executing == true) {
                self.refreshControl?.beginRefreshing()
            } else {
                self.refreshControl?.endRefreshing()
            }
        })
        .addDisposableTo(self.disposeBag)

thanks for the answer

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
alpiopio
  • 243
  • 1
  • 2
  • 10

1 Answers1

0

I think your problem is related to showing UIRefreshControll programically, as answered in: UIRefreshControl - beginRefreshing not working when UITableViewController is inside UINavigationController

I reproduced your issue (refresh controls not showing) and after applying this solution to code below everything is now working.

import UIKit
import RxSwift

class ViewController: UIViewController {

    let testObservable = PublishSubject<Bool>()
    let disposeBag = DisposeBag()
    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        Observable.just(true).delay(2, scheduler: MainScheduler.instance).subscribe(testObservable).disposed(by: disposeBag)
        tableView.refreshControl = UIRefreshControl()
        testObservable.observeOn(MainScheduler.instance).subscribe(onNext: { (executing) in
            print("Executing: \(executing)")
            self.tableView.refreshControl!.beginRefreshing()
            self.tableView.setContentOffset(CGPoint(x: 0, y: -self.tableView.refreshControl!.frame.size.height), animated: true)
        }).disposed(by: disposeBag)
    }
}
Forgetter
  • 16
  • 1
  • 2