1

My sport app keeps track of who is on and off the field, and for how long. I normally have 20-30 people to swap around, during training time. I have a timer to reload the visible cells of the collection view every second. The whole collection view reload can cost between 120-150ms.

The scrolling performance is good, however, sometimes the tapping to swap players does not respond. I think that is when the collection view is trying to reload the cells.

I can see there might a couple of ways:

  • Use UITableView, with each row to have 4 different elements.
  • Use UIScrollView, and preload all elements there. We used to use KKGridView library here, but it is way outdated. That is why we move to UICollectionView after 6-7 years

Have anyone had the same issue, and which way should provide the acceptable level of efficiency but not too complex to implement (to reduce the number of bugs)

CollectionView

vodkhang
  • 18,639
  • 11
  • 76
  • 110
  • you could disable reload while scrolling, e.g. http://stackoverflow.com/a/993304/22147 – Rhythmic Fistman May 18 '17 at 05:02
  • that wouldn't help, I don't have problems with scrolling – vodkhang May 18 '17 at 05:03
  • whoops, sorry, missed that. you could reload the cell yourself without asking the collection view to do it – Rhythmic Fistman May 18 '17 at 05:04
  • why dont just update the cell's view instead of reload whole visible cell? – Tj3n May 18 '17 at 05:09
  • Perhaps you could show some code as it isn't exactly clear what you are reloading; reloading the entire collection view isn't a good idea. – Paulw11 May 18 '17 at 05:25
  • @Tj3n: you mean to call [collectionView visibleCells] and then update the cell's element? – vodkhang May 18 '17 at 05:29
  • sometimes the tapping to swap players does not respond. means you are swapping by dragging cells? – elk_cloner May 18 '17 at 05:35
  • Something like that, just keep the record of the cell's index that need to update, then let the view inside the cell to update, if you push the update to the cell class, it wont mess with your collection view tap/drag... – Tj3n May 18 '17 at 05:36
  • will definitely try that, will tell you if it works – vodkhang May 18 '17 at 05:40
  • @elk_cloner everytime I tap, the cell changes from red to green or green to red. I don't need to drag the players around – vodkhang May 18 '17 at 05:41
  • That seems to work great, thank @Tj3n, silly me, never thought about that. I can give you an accepted answer, if you like. Please bring your comment to be an answer – vodkhang May 18 '17 at 05:47
  • You should look into using NSNotifications and observing them instead of reloading the whole UICollectionView – DatForis May 18 '17 at 05:53

1 Answers1

1

Keep the record of the cell's index that need to update, then get the Cell from collection view, call method ask it to update itself, push the view update to the cell class, it wont mess with your collection view tap/drag...

Reload whole collectionView is only needed when whole dataSource change, yours is simply cell-by-cell update as I notice

Tj3n
  • 9,837
  • 2
  • 24
  • 35