0

I have a UITabBarController with 2 controllers.

  1. In the first VC user have a list of articles. A user can add some article to favourite (realm database)
  2. The second VC it is a list with realm query (favourite article). When 2 controllers created (user tap to both of them), and in the first VC add article to favourite in the second collectionView does not show new item.

My favouriteVC collectionView binding

 private func setupBinds(){
    self.favArticleCollectionView.register(UINib(nibName: "PreviewItemVCell", bundle: nil), forCellWithReuseIdentifier: PreviewItemVCell.identifier)

    viewModel
        .articlesSubject
        .observeOn(MainScheduler.instance)
        .bind(to:
        self.favArticleCollectionView.rx.items(cellIdentifier: PreviewItemVCell.identifier, cellType: PreviewItemVCell.self)) { (item, article,cell) in
            cell.article =  article
    }.disposed(by: disposeBag)

and my favouriteViewModel which make a query from db

class FavouriteViewModel {
let articlesSubject: PublishSubject<[ArticleModel]> = PublishSubject()



func fetchDateFromDb(){
    print(Realm.Configuration.defaultConfiguration.fileURL!)
    let articleList = DatabaseManager.shared.getAllArticle().toArray()

    articlesSubject.onNext(articleList)
}}

Problem: When the controller has created, he does not update. How I can update it?

  • When do you trigger `fetchDateFromDb`? If it's trigger only once when the secondVC is loaded, then you won't get new data when user add to favourite. You could either refetch when appearing, or trigger `fetchDateFromDb` when adding / removing elements to the favourite. – Ben Oct 10 '19 at 03:29
  • @Ben I call it at the viewWillAppear method and it is always the last date – Vadym Marchenko Oct 10 '19 at 15:55

1 Answers1

0

The problem was with my custom layout for collection view. It is the right answer enter link description here