Hide navigation bar, but when I transition to the previous view (popped) it shows the old back button temporarily. Why?
The problem here is that viewDidLoad
is way too soon! Remember, viewDidLoad
does not have anything to do with the interface and the actual push animation. It does not mean that this view controller's view is about to appear on screen! It merely means that the view controller has obtained its view.
I made a video, showing what happens on my machine as I move back and forth between two view controllers in a navigation interface, one of which shows the navigation bar, the other does not: http://youtu.be/PxpchytWQ4A
To me, that's as coherent as you are going to get when showing and hiding the nav bar as you push and pop! Here's the code I used. The view controller that hides its nav bar is of class ViewController2. This code is in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after application launch. dispatch_async(dispatch_get_main_queue(), ^{ [(UINavigationController*)self.window.rootViewController setDelegate:self]; }); return YES;}-(void)navigationController:(UINavigationController *)nc willShowViewController:(UIViewController *)vc animated:(BOOL)animated { [nc setNavigationBarHidden:([vc isKindOfClass:[ViewController2 class]]) animated:animated]; }
That's all I did.
Hey why don't you use navigation bar as a UIToolbar
.
Instead Of hiding UINavigation
you can mimic navigation controller to UITootlbar
by adding buttons to it.
hiding unhiding UINavigation
would be complex.
I am Uploaded the dropbox link.
In the second view controller hide the nav bar in viewWillAppear::
self.navigationController.navigationBar.frame = CGRectMake(0, 0, 0, 0);
For unhiding the navigation bar set the frame in viewWillDisappear:
self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 44);