Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView in storyboard not updating content size on rotation

I'm working on project targeted for iOS 6 that leverages storyboards and auto layout. In the storyboard there are many places where a UITableView is added as a subview to a view controllers view. This table view uses prototype cells from the storyboard.

The issue we're running into is that if the view controller is initially loaded in landscape orientation and the device is then rotated to portrait, the table view begins to scroll both vertically and horizontally. The table views cells are drawn with the correct dimensions but there is additional white space to the right.

It appears that while the frame and bounds of the table view are being updated to the correct size on rotation, the table views content size is not. Regardless of any update rotation change the content size remains the same dimensions.

The issue doesn't present itself if programatic table view cells are used. A few garish work arounds I've found, 1.) calling reloadData or reloadRowsAtIndexPaths:withRowAnimation: 2.) manually setting the property contentSize.

Both of these seem less than ideal.

I've added this link to a dead simple sample project which demonstrates this issue. The only changes made are to the storyboard and the main view controllers implementation.

Before rotation Before rotation After rotation After rotation

like image 397
atommclain Avatar asked Sep 21 '12 23:09

atommclain


2 Answers

I'm having the same issue - can't seems to find any documented answer related to this. I ended up manually modifying the UITableView contentSize like you mentioned in:

- (void) viewWillLayoutSubviews
{
    self.tableView.contentSize = CGSizeMake(self.tableView.frame.size.height, self.tableView.contentSize.height);
}
like image 170
alexandria122 Avatar answered Oct 06 '22 12:10

alexandria122


I ran into this issue today and filed a bug report with Apple.

Appears that if you are using a custom cell with a UI element AND autoLayout, the UIScrollView content size is having problems.

If you remove all UI elements, OR turn off autoLayout, OR use a factory cell (basic, etc), all works fine.

like image 24
Ron_L Avatar answered Oct 06 '22 11:10

Ron_L