TableViewController not updating cells

后端 未结 2 1976
既然无缘
既然无缘 2021-01-26 11:12

This app allows Rider to request a ride and driver to accept the request. In this tableview are the rides the riders (2) have requested.

Unable to update tableviewcel

相关标签:
2条回答
  • 2021-01-26 12:03

    The callbacks from Geocoder are asynchronous and you can't simply change the values in the table cells by updating the label values inside the callback - you have to inform the table view to reload the cell in order to update it.

    So, you need to pull out the GeoCoder lookups from inside tableView:cellForRowAt and move them into a loop in either viewDidLoad or viewWillAppear. The final values should form part of you model.

    Inside the callbacks for the GeoCoder you would then tell the table view to reload each individual cell calling tableView.reloadRows with a single value array.

    0 讨论(0)
  • 2021-01-26 12:04

    make sure you reload tableview in main queue in with parameter closure.

    ref.child("drivers").child("RideRequests").observe(FIRDataEventType.value, with: { snapshot in
        self.rideRequests.removeAll()
        for item in snapshot.children{
            self.rideRequests.append(item as! FIRDataSnapshot)
        }
        self.rideRequests.reverse()
        DispatchQueue.main.async (execute: { () -> Void in
            self.tableView.reloadData()
        })
    })
    
    0 讨论(0)
提交回复
热议问题