6

I have a UIViewController (red) set as the first tab of a UITabBarController as shown in the storyboard below. This view controller is a container view controller and loads a UINavigationController inside its contentView (the white rectangle inside the red view controller).

Storyboard

This is my code for loading the navigation controller inside the red view controller's contentView:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // instantiate navigation controller
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *navigationVC = [storyboard instantiateViewControllerWithIdentifier:@"N"];

    // place navigation controller inside content view
    [self addChildViewController:navigationVC];
    navigationVC.view.frame = self.containerView.bounds;
    [self.containerView addSubview:navigationVC.view];
    [navigationVC didMoveToParentViewController:self];
}

From what I know about view controller containment this should work as I am explicitly setting the frame for the navigation controller. However, when there are enough cells in the tableView to exceed the container's height there is always a bar at the end of the tableView when I scroll down. I have set the tableView's backgroundColor to orange and the cell's backgroundColor to white in order to see the difference.

Gap at the end of the tableView

How do I get rid of that orange gap at the end of the tableView?

(Note: I am not using autolayout and I need a solution that works for both - iOS7 and iOS6.)

Mischa
  • 15,816
  • 8
  • 59
  • 117
  • set the tableView's background colour as nil, then wt's the problem with that . – Kumar KL Apr 28 '14 at 11:55
  • The color of the `tableView` doesn't matter. It's the gap or the "extra row" that shouldn't be there. – Mischa Apr 28 '14 at 11:59
  • 1
    I think that child VC (navigation controller) is respecting the parent tab bar. – damirstuhec Apr 28 '14 at 12:01
  • I agree. The question is: How do I make the table view controller understand that it should *not* respect the parent tab bar itself? Because obviously the navigation view controller adjusts its height with respect to the tab bar correctly and it's not the table view's job to do that... – Mischa Apr 28 '14 at 14:09
  • Did you end up figuring this out? – Pascal Bourque Oct 11 '14 at 01:03
  • Did you figure that out? Maybe `containerVC.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;` can work? – rohan-patel Feb 19 '16 at 19:27

2 Answers2

4

I know you are also looking for an answer which works on iOS 6, but on iOS 7 and above you can use

self.extendedLayoutIncludesOpaqueBars = YES;
kaischo
  • 148
  • 1
  • 8
  • It also can be defined on InterfaceBuilder on Attributes Inspector -> View Controller -> Extend Edges: Under Opaque bars – BuguiBu Sep 25 '18 at 11:50
0

Have you tried setting self.edgesForExtendedLayout = UIRectEdgeAll; in -(void)viewDidLoad of Table View Controller - Root?

Note: iOS 7 only

damirstuhec
  • 6,069
  • 1
  • 22
  • 39
  • I need a solution that works for iOS 6 as well (updated my question). But I have also tried your suggestion and it did not work in iOS 7. – Mischa Apr 28 '14 at 11:56