I trigger from uiviewcontroller to viewmodel and updates view but from uiview even fetching data with urlsession works tableview reload is not working

21 views Asked by At

this is my viewmodel fetching func I run it at the beginning with id = 0

 func fetchLocationWithQuery(with id: String) {
        NetworkManager.shared.request(type: LocationResult.self, url: "https://rickandmortyapi.com/api/location/\(id)", method: .get) { response in
            
            switch response {
            case .success(let success):
                if success.id != nil {
                    guard let data = success.residents else {
                        return
                    }
                    self.view?.updateTableView(chracters: data)
                    //   print(data)
                }
            case .failure(let failure):
                
                print(failure)
            }
        }
    }

then this is update func

   
    func updateTableView(chracters: [String]) {
        viewModel.tableViewCharacterUrlArray = chracters
        
        DispatchQueue.main.async {
            self.tableView.reloadData()
        }
    }
    

This works with swiping too

But i have a header uiview for tableview it triggers I can see the response but not triggering self.view.updateTable func in ViewModel

extension CellHeader: UICollectionViewDelegate {
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let arr = viewModel.locationResponseForCollectionView
        guard let query = arr[indexPath.item].id else {
            return
        }
       // print(query)
        viewModel.fetchLocationWithQuery(with: String(query))
        
    }
    
    
}
0

There are 0 answers