I have a UINavigationController and in one of it's view controller, I am making the toolbar not hidden in viewDidAppear. Works just fine. But, in viewDidDisappear, I am setting it as hidden but it does not get hidden. What am I doing wrong? Here's the relevant code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self navigationController] setToolbarHidden:NO];
UIBarButtonItem *buttomSubmit = [[UIBarButtonItem alloc] initWithTitle:@"Submit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *buttonPrint = [[UIBarButtonItem alloc] initWithTitle:@"Print"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *buttonUnits = [[UIBarButtonItem alloc] initWithTitle:@"Units"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
[self setToolbarItems:[NSArray arrayWithObjects:buttonUnits, flexSpace, buttomSubmit, buttonPrint, nil]];
[buttomSubmit release];
[buttonPrint release];
[buttonUnits release];
[flexSpace release];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[self navigationController] setToolbarHidden:YES];
}
Thanks!
viewDidDisappear
is called after the view has gone off screen. If the view has gone off screen because of pressing the back button it will have been popped off the navigation controller stack.
From the UIViewController class reference notes on the navigationController property:
Only returns a navigation controller if the view controller is in its stack. This property is nil if a navigation controller cannot be found.
This means that [self navigationController]
is returning nil and therefore the setToolbarHidden
message is sent to nil and has no effect.
To hide it after the new view loads which is what you seem to want you could do the hiding in the viewDidAppear
method of the new view's controller instead.