ContentInset isn't set when using a UITableView in a UIViewController that is displayed using UIViewControllerContainment

Originator:bryn.bodayle
Number:rdar://16042338 Date Originated:
Status:Closed Resolved:10/31/17
Product:iOS Product Version:7.0
Classification: Reproducible:Always
 
Summary:
I'm using a segmented controller in a UINavigationController's navigationBar to switch between several view controllers using the UIViewControllerContainment API. The contentInsets and scrollViewIndicatorInsets are correctly set for the first view controller, but not the second view controller after I switch to it.


There is a workaround that requires manually setting the tableview insets based on the parent's top and bottom layout guides.

Steps to Reproduce:
I've created a sample project which is the simplest and easiest way to see the problem. I've made the code very concise and simple so you can see what is going wrong.

1. Build and run the sample project on the simulator or device.
2. While on the "GREEN" tab, scroll up and down and see that at the contentInsets and scrollViewIndicatorInsets are not clipped by any view and content appears behind the tabbar and navigation bar.
3. Switch to the "RED" tab via the segmented controller button.
4. Scroll up and down on the tableview and see that the contentInsets and scrollViewIndicatorInsets are incorrectly set and cause content to be inaccessible behind the tabbar and navigationcontroller.

Expected Results:
Scrolling up and down on the "RED" tableview and seeing that at the contentInsets and scrollViewIndicatorInsets are not clipped by any view and content appears behind the tabbar and navigation bar.

Actual Results:
The content and scrollViewIndicatorInsets are clipped by the navigation bar and tabbar.

Version:
iOS 7.0.4

Notes:
Adding this code to the view controllers which are presented will fix the issue.

- (void)didMoveToParentViewController:(UIViewController *)parent
{
    if (parent) {
        CGFloat top = parent.topLayoutGuide.length;
        CGFloat bottom = parent.bottomLayoutGuide.length;
        
        if (self.tableView.contentInset.top != top) {
            UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0);
            self.tableView.contentInset = newInsets;
            self.tableView.scrollIndicatorInsets = newInsets;
        }
    }
    
    [super didMoveToParentViewController:parent];
}

Configuration:
iOS 7
iPhone 5s
Xcode 5.0.2 and Xcode 5.1 Beta 4
OSX Mavericks


Here is the sample project:
https://www.dropbox.com/s/xlsy8z2ozaixjlx/SegmentedController.zip

Comments


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!