[英]Hiding a superview controller's UINavigatonBar from within a subview's controller?
我正在构建一个由 UINavigationController 控制的具有多个屏幕的大型分层 iPhone 应用程序。 其中一个屏幕能够以两种不同的格式显示内容(我使用 IB 创建的 UITabBar 在它们之间切换),并且我已经使用基于活动添加子视图(从 nib 文件加载)的视图构建了这个屏幕标签。
这些子视图中的每一个都包含一个搜索栏,当导航栏被点击时需要将其推开。 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. 加载子视图时,会设置其“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];
在这两种情况下,酒吧都没有以任何方式改变。 我是否必须告诉导航栏以某种方式更新? 有没有更好的方法来实现我想要的功能?
我知道前向声明工作正常,因为我可以使用将新视图推送到 navigationViewController
NewViewController *newViewController = [[NewViewController alloc] initWithNibName:@"NewView" bundle:nil];
[self.superViewController.navigationController pushViewController:newViewController animated:YES];
[newViewController release];
在此先感谢,朱利安 Ceipek
万一重要,导航栏设置为半透明,以便子视图位于栏下方。
您是否尝试过使用模态视图 controller? 根据每个选择,如果您将模态视图 controller 推送到视图上,它将自动隐藏导航栏。
本质上,它是一个用于临时接受用户数据的屏幕。 如果您实现此功能,它将在导航栏进入视图时自动隐藏,因为它由呈现它的视图 controller 拥有,并且不会推送到导航 controller 堆栈上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.