I'm using Auto-layout for cells (UITableViewCell and UICollectionViewCell), but noticed a significant performance drawback when the cells are re-used and I wonder what could I do to improve it.
Maybe it is due to the way I create/configure cell, in my app I need to show books as cells, and different book genres have different layout, but I only have one BookCell, I re-configure constraints when the cell is created/reused for a particular Book based on the book's genre.
From my understanding, in my case, auto-layout should be slower than fixed frame as the steps are as follows:
auto-layout
- remove current constraints
- re-add constraints depending on book's genre
- set all labels / image views for the book
I think internally at step 2 iOS will re-run the constraints solver and at step 3 will re-adjust constraints (ie re-run the solver) to satisfy all labels and image views with text and images set.
fixed-layout
(have a list of different frames for labels, image views, for different genre) 1. re-set all labels', image views' frames 2. set labels' text and image views' images
It takes me some time to convert all auto-layout cells to use fixed frames, and the things I can think of, in order to improve the performance are:
- duplicate the generic BookCell, and make one cell for each genre.
- set all labels, image views, before setup constraints
- not too sure about this, should I add auto-layout constraints in
updateConstraints
method, or in the initializer (e.g.initWithTableViewCellStyle:reusableIdentifier:
)?
Thanks a lot!