Unal Celik
Unal Celik

Reputation: 196

tableView.reloadData() every time view appears

I'm working on a social app like Instagram, with Firebase. Where users share their photos in main screen and in their profile too. My problem is when user1 liked user2's picture2 in main screen and visits user2's profile the like value for that picture2 is still the same until cell is reloaded.

If i scroll down and come back to picture2 cell is reloading and it'll have correct like value. Because i'm using didSet{} in my cell, where the fetching like value is done. But that's a bad user experience. So my solution was reloading collectionViews every time.

Is that a bad thing for performance or there are any other issue about that?

Upvotes: 1

Views: 510

Answers (1)

Darshan Kunjadiya
Darshan Kunjadiya

Reputation: 3329

You can do it like below:

Objective C

NSArray *visibleCells = [_tblWhoAreYou visibleCells];
for (WhoRUSWCell *cell in visibleCells) {
   NSIndexPath *indexPath = [_tblWhoAreYou indexPathForCell:cell];
   cell.imageStatus.image=[UIImage imageNamed:@"greenCircle.png"];
   [cell setNeedsLayout]; // OR you can reload particular cell
}

Swift 3.0

var visibleCells: [Any] = self.tblWhoAreYou.visibleCells
for cell: WhoRUSWCell in visibleCells {
    var indexPath: IndexPath? = self.tblWhoAreYou.indexPath(for: cell)
    cell.imageStatus.image = UIImage(named: "greenCircle.png")
    cell.setNeedsLayout() // OR you can reload particular cell
}

Using this you can directly update image directly without reloading. You just have to check your tag or anything else for find your selected object which you want to update.

Upvotes: 2

Related Questions