WWDC 2014 – New in Table and Collection Views – V226

To use Dynamic Type in custom labels:
use preferedFontForTextStyle

iOS 8 CellSizing
First the tableview uses an estimated cell size. Once the cell needs to be displayed in screen:
1) Create Cell
2) Size cell
3) Update contentsize
4) Display cell

Self-sizing Cells
– Using Autolayout, if constraints are determined unambiguously nothing needs to be done, the autolayout engine returns back the correct size.

or

– Manual-sizing: override -sizeThatFits:

Autolayout:
– use tableView.estimatedRowHeight instead of rowHeight
– If tableView comes from nib file or story board. RowHeight will be set when it comes out of the nib so you need to set: tableView.rowHeight = UITableViewAutomaticDimension. this is the new default rowHeight.

Differences with iOS 7 on Dynamic sizing for Cells
iOS7
rowHeightForCellAtIndexPath:
This was called for ALL the cells on creation of the table view. So if we have 22000 cells to display this was called that many times. Cell size was difficult to provide, as the cell wasn’t created yet.

iOS8
Works with estimated cell height, once the cell is about to be displayed on screen then the real size is calculated and can even be retrieved automatically from AutoLayout.

Self-sizing Cells in CollectionView FlowLayout
Very similar to table view using size instead of only height.
estimatedItemSize instead of itemSize.

High-performance Layouts
iOS7 introduced invalidation contexts. Flow layout uses this for rotation, in iOS 8 used for self-sizing cells

iOS 8 improves on:
– floating headers
– avoid visual jumps with self-sizing cells

TODO: Research more about Invalidation contexts

Leave a Reply

Your email address will not be published. Required fields are marked *