0

I have a custom section header in my UITableView that contains A UICollectionView of some avatar images. The data is sourced once and cached for the images (images change so infrequently that it doesn't warrant real time updates).

I was hoping to make it so this header never redraws again even if the UITableView refresh is called. The reasoning for this is every time you take action, it causes the images to flicker as they're being redrawn from their default anonymous silhouette to the actual image of the person. The images are cached, but it doesn't matter because

I assume this is not possible by design - a UITableView will destroy everything and reload it all over again every time the refresh is called, correct?

I just wish I could hook into the refresh and preserve the section header, and reload the rows only.

Thanks for any ideas/guidance, I know this is a little uncommon but I don't want to move the header out into its own view because i'm using a UITableViewController directly, and it would be a real pain to have to embed it in a containerview and all that.

NullHypothesis
  • 4,286
  • 6
  • 37
  • 79
  • You could try putting the section header into its own section and when you reload the table, only reload the other section. Another option would be to store a variable somewhere for 'firstLoad' and configure the section header differently based on whether or not it's the firstLoad. – nicksarno May 18 '20 at 22:54

1 Answers1

0

Yes, even you cached the image and set by local or something, it will take time to load. If you are using lazy loading, it will be splash ( for sure :) ). So, the only possible thing is, you have to update your tableView after refreshing is using tableView.beginUpdates and tableView.endUpdates. Input some add cell or remove cell base on the data after refreshing

King.lbt
  • 843
  • 5
  • 15
  • Hmm that is interesting - can you elaborate ab it on the beginUpdates and endUpdates part? I've never worked with it – NullHypothesis May 19 '20 at 03:51
  • `tableView.beginUpdates() tableView.deleteRows(at: [IndexPath(row: 0, section: 0), with: .automatic) tableView.insertRows(at: [IndexPath(row: 1, section: 0), with: .automatic) tableView.endUpdates()` It's something like this. Make sure your datasource items is the same with the rows of the tableView. Otherwise, it will be crashed – King.lbt May 19 '20 at 03:54
  • where am I adding this code, to the table redraw event? – NullHypothesis May 19 '20 at 04:00
  • Replace reloadData with it – King.lbt May 19 '20 at 05:49