I have two UITableViewControllers embedded in separate fullscreen container views within a single view controller, with a segmented control bar button item to toggle between them (like in the App Store's top charts). Since there are two scroll views in the view controller, I have to manage their insets manually (as stated in the class reference). What is the proper way to do this in iOS 7 with auto-rotation?
This is what I have right now, in my UITableViewController subclass implementation:
- (void)viewWillAppear:(BOOL)animated
{
portraitEdgeInsets = UIEdgeInsetsMake(64.0, 0.0, 44.0, 0.0);
landscapeEdgeInsets = UIEdgeInsetsMake(52.0, 0.0, 32.0, 0.0);
[_fileTable setScrollIndicatorInsets:portraitEdgeInsets];
[_fileTable setContentInset:portraitEdgeInsets];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIDeviceOrientationPortrait) {
[_fileTable setScrollIndicatorInsets:portraitEdgeInsets];
[_fileTable setContentInset:portraitEdgeInsets];
}
else {
[_fileTable setScrollIndicatorInsets:landscapeEdgeInsets];
[_fileTable setContentInset:landscapeEdgeInsets];
}
}
It almost works, but if the table view is scrolled all the way to the top in landscape mode before rotating to portrait, it will be scrolled down 12 pixels because of the previous inset (the inset is correct; the table view just isn't scrolled all the way to the top). I've noticed that for table views that are inset automatically the opposite happens: if they are scrolled all the way to the bottom in landscape they will be scrolled 12 pixels up from the bottom when returning to portrait. That isn't a problem. I'm just trying to get both table views behaving like automatically inset ones.