从子视图控制器中隐藏超级视图控制器的 UINavigatonBar?
我正在构建一个大型分层 iPhone 应用程序,其中包含由 UINavigationController 控制的多个屏幕。其中一个屏幕能够以两种不同的格式显示内容(我使用 IB 创建的 UITabBar 在它们之间切换),并且我使用一个视图构建了这个屏幕,该视图添加了一个基于活动的子视图(从 nib 文件加载)选项卡。
每个子视图都包含一个搜索栏,点击该搜索栏时需要将导航栏推开。导航栏只能从子视图的超级视图的控制器访问,因此我将超级视图的控制器类的前向声明添加到每个子视图的控制器中。当子视图被加载时,它的“superViewController”属性被设置。
通常,每个搜索栏都会根据需要自动隐藏导航栏,但我需要自己实现此功能,因为导航栏位于搜索栏上方的视图中。我尝试通过
[self.superViewController hideNavBar];
在方法中
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView
使用来做到这一点,其中“hideNavBar”在 superViewController.m 中定义如下:
-(void)hideNavBar {
[self.navigationController setNavigationBarHidden:TRUE animated:TRUE];
}
并且我还尝试直接隐藏栏
[self.superViewController.navigationController setNavigationBarHidden:TRUE animated:TRUE];
。在这两种情况下,栏都没有以任何方式改变。我是否必须告诉导航栏以某种方式更新?有没有更好的方法来实现我想要的功能?
我知道前向声明工作正常,因为我可以使用
NewViewController *newViewController = [[NewViewController alloc] initWithNibName:@"NewView" bundle:nil];
[self.superViewController.navigationController pushViewController:newViewController animated:YES];
[newViewController release];
“提前感谢”将新视图推送到 navigationViewController 上, Julian Ceipek
以防万一,导航栏设置为半透明,以便子视图位于导航栏下方。
I am building a large hierarchical iPhone application with multiple screens controlled by a UINavigationController. One of these screens is able to display content in two different formats (I toggle between them using an IB-created UITabBar), and I have constructed this screen with a view that adds a subview (loaded from a nib file) based on the active tab.
Each of these subviews contains a search bar that needs to push the navigation bar out of the way when it is tapped. The navigation bar is only accessible from the subviews' superview's controller, so I have added a forward declaration of the superview's controller class to the controller of each subview. When a subview is loaded, its "superViewController" property is set.
Typically, each search bar would automatically hide the navigation bar as necessary, but I need to implement this functionality myself because the bar is in the view above the search bars. I have tried doing this by using
[self.superViewController hideNavBar];
in the
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView
method, where "hideNavBar" is defined as follows in superViewController.m:
-(void)hideNavBar {
[self.navigationController setNavigationBarHidden:TRUE animated:TRUE];
}
and I have also tried hiding the bar directly with
[self.superViewController.navigationController setNavigationBarHidden:TRUE animated:TRUE];
In both cases, the bar did not change in any way. Do I have to tell the navigation bar to update somehow? Is there a better way to implement the functionality I want?
I know that the forward declaration is working properly because I can push a new view onto the navigationViewController using
NewViewController *newViewController = [[NewViewController alloc] initWithNibName:@"NewView" bundle:nil];
[self.superViewController.navigationController pushViewController:newViewController animated:YES];
[newViewController release];
Thanks in advance,
Julian Ceipek
In case it matters, the navigation bar is set to be translucent so that the subviews are underneath the bar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用模态视图控制器?根据每个选择,如果将模态视图控制器推到视图上,它将自动隐藏导航栏。
http://developer.apple.com/library/ios/ #featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
本质上它是一个用于临时接受用户数据的屏幕。如果您实现此功能,当导航栏进入视图时,它将自动隐藏导航栏,因为它由呈现它的视图控制器拥有,并且不会被推送到导航控制器堆栈上。
Have you tried using a modal view controller? Based on each selection, if you push a modal view controller onto the view it will automatically hide the navigation bar.
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
Essentially it is meant to be a screen that is used to temporarily accept user data. If you implement this it will automatically hide the navigation bar when it comes into view as it is owned by the view controller that presents it and is not pushed onto the navigation controller stack.