Add a UINavigationController nested inside a container view controller to a UITabBarController - ios

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).
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.
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.)

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;

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

Related

View controller is obscured when pushing a navigation controller

I have a navigation controller and a view controller inside of the navigation controller.
The view controller calls the navigation controller to push a view:
`MYVC *myvc = [MYVC new]`;
`[self.navigationController pushViewController:myvc
animated:YES]`;
Inside of MYVC I have the following logic for laying out my collection view:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_collectionView.frame = CGRectMake(0,
0,
self.view.frame.size.width,
self.view.frame.size.height - height);
}
This works fine for when I first load my vc as the collection view is loaded under my nav bar.
However when I push my vc it looks like the following:
Above the divider line is my nav bar and the red is my colleciton view.
It looks like the collection view is laid out under my navigation bar. If I drag on my collection view it lays out properly.
If I try changing the _collectionView frame's y position to
self.navigationController.navigationBar.frame.size.height however I get a large whitespace above my collection view after I drag on my collection view. How can I get it to be laid out properly the first time? Do I have to force layout? Is there some reason my nav bar isn't taken into account for the vc until I drag in the scroll view?

tableView wierd behaviour while pushing in navigation controller

I am having some issue while pushing a viewController in UINavigationcontroller .
What i have is , a UITabBar and when click on the button it loads new viewController in UITabBar's UINavigationcontroller .
I am using this to push it ...
UIStoryboard * storyboard = self.storyboard;
loginEmailinviteViewController * detail = [storyboard instantiateViewControllerWithIdentifier:#"loginEmailInvite"];
[self.navigationController pushViewController: detail animated: YES];
Every thing is perfect but the only problem occurs in tableview which looks wierd there . It takes some space above its starting point as if it is on navigation bar .
Please check and help me .
Thanks
This is another tricks,,
In Your Story Board,
Drag View Controller
Embed with Navigation Controller
Drag Table View [Not Table View Controller] and put in View Controller
Check the Table View's Y position in Size Inspector
If it shows 64 or anything, change to 0
Drag Table View Cell and put in Table View
Cell will not get down.
In your view did load add following line :
self.automaticallyAdjustsScrollViewInsets = NO;

Is it possible to change frame of view controller in UITabBarController so that UITabBarController view will be visible?

I have my own subclass of UITabBarViewController.
Is it possible to change frame for all embedded viewcontrollers' views so that own UITabBarViewController view will be visible partially?
On the attached image I set purple color for own tabBarController view.
I want to change frame of each selected view controller so that this purple view (UITabBarController view) will be visible.
I stumbled upon this answer looking for a solution myself, and found an okayish way to handle this: wrap your viewController inside another viewController as a childViewController.
Essentially, you would present a viewController with clear background, which has your content controller as childController with a frame you want it to have:
UIViewController *wrapperController = [UIViewController new];
wrapperController.backgroundColor = [UIColor clearColor];
[wrapperController addChildViewController:vc];
[wrapperController.view addSubview:vc.view];
vc.view.frame = CGRectMake(...);
Just make sure to pass the tabbarItem to the wrapper, and use that one instead of the child.

Navigation controller moves all views down by 64px in Storyboard despite it being hidden.

In the View Controller, I set the navigation bar so that
self.navigationController.navigationBar.hidden = YES;
However, I am running into the issue that whichever way my UIViews are laid out in Storyboard, all the UIViews at runtime are moved down 64px. Is there a way that I could set so that both the NavBar is hidden, and that it does not affect how the UIViews are laid out on screen?
Thanks!
Usually , I use this to hide navigationBar.
[self.navigationController setNavigationBarHidden:YES];
While,
self.navigationController.navigationBar.hidden = YES;
Is the property for UIView, this is a method for UINavigationController.

Resize UITableViewController for display in a popover

I have a UITableViewController that I am trying to display in a UIPopoverController. No matter what do, the tableview is always displayed at full size within the popover.
In my StoryBoard I've set the UITableViewController's Size to Freeform. I've explicitly set the UITableView's height and width in the Size inspector.
Here is how I setup the controller and popover:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard-iPad" bundle:nil];
self.settingsController = [sb instantiateViewControllerWithIdentifier:#"SettingsViewControllerID"];
self.settingsPopover = [[UIPopoverController alloc] initWithContentViewController:_settingsController];
I've also tried setting the controller's popover size explicitly:
self.settingsController.contentSizeForViewInPopover = CGSizeMake(400.0, 400.0);
When I run the app and activate the popover - it is almost as tall as the main screen.
Am I missing something obvious here?
Thanks in advance,
CS
You can change the tableView size by using below code.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIStoryboardPopoverSegue *popoverSegue;
popoverSegue = (UIStoryboardPopoverSegue *)segue;
UIPopoverController *popOverController = popoverSegue.popoverController;
[_popOverController setPopoverContentSize:CGSizeMake(width, height)];
}
The UITableViewController always wants to be the full size of the window, or popover (which is a special kind of window). If you want a smaller table view, use a UIViewController instead as the content controller of your popover. You should then be able to resize it in IB.

Resources