iphone – setNavigationBarHidden:在removeFromSuperview之后
我在我的Detail View Controller顶部添加了一个UIWebView子视图,它有一个导航栏.我想在WebView子视图中隐藏导航栏,并在从superview中删除时再次显示它,以便在查看WebView时有更多的屏幕空间.
我的代码的问题是添加子视图后导航栏被成功隐藏,但是当删除子视图时尝试再次显示导航栏时它不起作用. 任何帮助将非常感激.谢谢. 这是我的代码: // 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 setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view.superview cache:YES]; [self.view removeFromSuperview]; [self.navigationController setNavigationBarHidden:NO animated:YES]; [UIView commitAnimations]; } 解决方法
对于我在代码中看到的内容:
– 您正在向InstrumentDetailViewController实例主视图添加子视图. – 子视图是WebViewController实例的主视图. 但是…… WebViewController永远不会被推送或弹出到您的导航堆栈.因此,您的WebViewController实例没有对navigationController的引用,并且调用[self.navigationController]会将您的setNavigationBarHidden:NO animated:YES消息发送给… nil 您可以: [[[self parentViewController] navigationController] setNavigationBarHidden:NO animated:YES]; http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html 搜索addChildViewController: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |