Search code examples
swiftuitableviewreloaddata

tableView.reloadData doesn't update UI


I've read many solutions, they didn't help me

I have table view which is added to my viewcontroller. I dragged it as outlet to controller.

 @IBOutlet weak var tableView: UITableView!

In viewDidLoad I added

tableView.dataSource = self
tableView.delegate = self

I have method to update data in table:

private func updateModel() {
    guard let chatUid = UsersManager.sharedInstance.currentChatUID() else { return }

    RealtedUserApi().getRelatedUser("\(chatUid)", successHandler: {  (relatedUsers) in

        dispatch_async(dispatch_get_main_queue()) {
            self.relatedUsers = relatedUsers
            self.tableView.reloadData()
        }
    }) { (error) in
        print(error)
    }
}

which is executed when I do pull-to-refresh, but UI isn't updated

I placed breakepoint in my table cell and there data from server (for instance user's status) are updated, but UI doesn't - user's status in view remains the same in cell's label

Does anyone have any ideas how to fix this?

p.s. relatedUsers is array of object RelatedUser. It's source for my tableView. RelatedUser has status property, which is changed on server and I need to update appropriate label text in cell


Solution

  • The problem was so silly, so it's shame on me:

    I commented some part of code in dequeueReusableCellWithIdentifier block where also was return cell and forgot about that. But in the end of cellForRowAtIndexPath I return UITableViewCell().

    Usually In this case App crashes, but in my case It didn't. So I could see rows with data from server, but update didn't work.