I am using a UINavigationController (side note: inside a UITabBar) which by default gives you a UINavigationBar on the top. If I hide the bar through IB, the bar is gone not only for the root UIViewController but also for all the controllers I push onto the stack. Leaving me no (automatic) way to pop back.
So how can hide the UINavigtionBar only on the root UIViewController. Switching on/off "navigationBarHidden" temporarily does not work as this looks awkward with the animation.
Any other ideas?
I actually ran into this problem, how i solved it was with the UINavigationCOntroller delegate, i basically have a UINavigationController subclass and made it its own delegate, then i implemented the method
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if([viewController isKindOfClass: [SomeClass class]])
[self setNavigationBarHidden: NO];
else
[self setNavigationBarHidden: YES];
}
So you ask which class it is and if its one that needs to have a navigationBar you show it, this worked for me pretty well...hope it helps
For me the easiest way to avoid the white space after hided the UInavigationBar is to hide or show your UInaviagtionBar as follow.
-(void)viewWillDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
with the syntax : self.navigationController.navigationBarHidden = YES;
i always have the white space.
My idea would be to not make your first view part of the navigation controller. Have a simple TableViewController, for instance, and then when you want to drill down, create the UINavigationController, and push it's view in manually.
I haven't tried this and don't know whether it'll work, though. Just an idea to try.
You have a couple of different nasty ways you can do it. The fact that you are embedded in a UITAbBar controller actually significantly complicates this because there is no way to distinquish whether viewDidAppear: is called due to the controller being pushed or from tab swapping, meaning you may need to stash data somewhere in order to know what is causing the transition and whether you need to hide the bar or not.
Assuming you handle that, one option is to change navigationBarHidden after you have animated in. On the way out there is no good place to handle that since you want the pop animation to happen after the bar animates. The quickest solution is to hide the bar then manually run your runloop for ~0.5 seconds until it animates out then continue. Its gross but it is quick and it works.
- (void)viewWillDisappear:(BOOL)animated {
if (animated) {
[self.navigationController.navigationBar setHidden:YES animated:YES];
}
//GROSS
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:0.5];
while([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate]);
}
If you want to do it cleanly, I recommend reimplementing UINavigationController from scratch.