setNavigationBarHidden:NO Not Working after removeFromSuperview
I am adding a UIWebView subview on top of my Detail View Controller which has a navigation bar. I would like to hide the navigation bar when in the WebView subview and reveal it again when removing from the superview, so that there is more screen room while viewing the WebView.
The problem with my code is that the navigation bar is successfully hidden after adding the subview, but it doesn't work when trying to reveal the navigation bar again when the subview is removed.
Any help would be much appreciated. Thank you.
This is my code:
// In InstrumentsDetailViewController.m
- (IBAction)edu1Link:(id)sender {
_webViewController = [[WebViewController alloc]
initWithNibName:@"WebViewController" bundle:nil];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft
forView:self.view cache:YES];
[self.view addSubview:_webViewController.view];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[UIView commitAnimations];
}
// In WebViewController.m
- (IBAction) doneButton:(id)sender {
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTran开发者_C百科sition: UIViewAnimationTransitionFlipFromRight
forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[self.navigationController setNavigationBarHidden:NO animated:YES];
[UIView commitAnimations];
}
For what I see in the code: - you are adding a subview to your InstrumentsDetailViewController instance main view. - The subview is the main view of a WebViewController instance.
But...the WebViewController is never pushed or popped to your navigation stack. For this reason, your WebViewController instance has NO reference to your navigationController, and calling [self.navigationController] will send your setNavigationBarHidden:NO animated:YES message to...nil
You can: - push/pop your WebviewController instance to the navigation stack, so it will have a reference to the navigationController. or - add your WebViewController instance as a CHILD of the InstrumentsDetailViewController and then call
[[[self parentViewController] navigationController] setNavigationBarHidden:NO animated:YES];
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
search for addChildViewController:
精彩评论