I have 200+ uiLabels on a long scrollview, I need to improve scrolling performance. Is it better to hide and unhide labels, or release them and recreate them, when they are out of view?
I have put tags on them, I am currently using those to hide / unhide with:
for (int i=0; i<42; i++) {
[theScroller viewWithTag:i].hidden = NO;
}
and visa versa, triggered by scroll contentOffset.y values..
I have my uiLabels collection in a plist so its also easy to release and rebuild them?
thanks for any help..
@Mark yes it would be better to release the labels,as if they are out of view,not in use,so they will improve the performance and also help you for memory management.
Having 200+ views reduces performances due to:
- Memory usage
- Display management / animations
It would absolutely be better to remove and release hidden labels and recreate them when needed: memory footprint would be lower and the superview would have only a few subviews to manage (plus the overhead of recreating labels is not so high).
If your scrollview + labels behavior is close to what a table view does, there is room for further improvement: label reuse. Remove hidden labels from their superview, change their title / style and re-add them at their new position.
One thing that may help performance is to set your labels as opaque. The performance will decrease when using views with transparent backgrounds.
Creating them on the fly is definitely a solution, however, you may notice that the scrolling may hang every now and then or that the labels will not appear only after a short while after you've scrolled.
Another solution would be to use the approach from this article. The idea is that you would pre-render the labels on the view and end up with a single static view that should work pretty nicely when you're scrolling around.
You can try using a tableView insteand of scroll view if each label is rigid.
Use a custom table cell and each cell have your label.