UITableViewCell's content view has wrong size after layouting

Originator:michaelhochs
Number:rdar://18290376 Date Originated:10-Sep-2014
Status:Open Resolved:
Product:iOS SDK Product Version:iOS8 GM
Classification:Other Bug Reproducible:Always
 
Summary:
When you ask the contentView of UITableViewCell for its size the returned frame is only correct if the cell has already been rendered or the cell does not have any type of accessory view or accessory type. This is a problem if you want to calculate the height of a table view cell based on its layout as you have no chance to figure out the size of the contentView inside the tableView:heightForRowAtIndexPath: delegate method.

Steps to Reproduce:
1. Open the given example project or create a new table view controller
2. In tableView:heightForRowAtIndexPath: dequeue a table view cell
3. set the accessory type of the table view cell to UITableViewCellAccessoryDisclosureIndicator
3. ask the table view cell's contentView for its frame.
4. call layoutIfNeeded
5. redo step 3.

Expected Results:
- In step 3 the content view returns the full size of the cell: {{0, 0}, {320, 44}}
- In step 5 the content view returns the final size that is used to render it: {{0, 0}, {286, 43.5}}

Actual Results:
- In step 3 the content view returns the full size of the cell: {{0, 0}, {320, 44}}
- In step 5 the content view returns something in between: {{0, 0}, {294, 44}}

Version:
iOS8 GM, Xcode 6 GM

Notes:
The biggest problem here is the wrong width, not the height that is wrong by 0.5pt. Without the correct width it is impossible to calculate the height of a label properly.

The sample project outputs logs that show the different rect values in the described states.

Configuration:
iPhone 5S / iPhone 6 Simulator

Comments

Any luck?

Hi there, just wondering if you've had any communication from Apple on this one? As far as I can see it's still an issue (And causes us a lot of pain!). Any news would be good news! Thanks, Simon


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!