1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Unal Celik
  • 186
  • 3
  • 13
  • It is kind of bad for performance, you may want to only reload the last row... Check this out: [Refresh Certain Row of UITableView based on int in Swift](http://stackoverflow.com/questions/28206492/refresh-certain-row-of-uitableview-based-on-int-in-swift) – Mr. Xcoder Feb 10 '17 at 11:13
  • Please share some code and if possible than problem picture share – Lalit kumar Feb 10 '17 at 11:18
  • @Xcoder123 it's actually not the last row. They're sorted chronically and can't say where it's corresponds in profile page, so reloadRowsAtIndexPaths() won't work for me until I rearrange my methods i think. – Unal Celik Feb 10 '17 at 11:30
  • @UnalCelik is my answer useful for you ? – Darshan Kunjadiya Feb 10 '17 at 12:14

1 Answers1

2

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.

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
  • Can you give me some more information about that. I'm beginner at development and i'm using Swift. And actual question was, is it a bad thing to reload collectionView everytime view appears. Thanks. – Unal Celik Feb 11 '17 at 07:18
  • @UnalCelik if you doit like my answer then you don't want to reload collectionView everytime. Without reloading you can able to update anything in your cell. – Darshan Kunjadiya Feb 11 '17 at 09:32
  • It works like charm... The only thing that didn't work for me was setNeedsLayout(). I used collectionView.reloadItems(at: [indexPath]) instead of that. You may want to edit it for other newbies :) Thanks! – Unal Celik Feb 11 '17 at 14:07