[英]iOS Tab Bar Controller : home message without tab item selected
I have built an iOS application based on a tab bar controller
with several view controllers
. 我已经建立了一个基于带有多个
view controllers
的tab bar controller
的iOS应用程序。
When the application starts, the view of the first view controller appears (normally). 当应用程序启动时,第一个视图控制器的视图出现(正常)。
I would like to print a "home message" that is not related to a view controller of the tab bar. 我想打印与选项卡栏的视图控制器无关的“家庭消息”。 When the user clicks on a tab, then the associated view is printed.
当用户单击选项卡时,将打印关联的视图。
Is this possible? 这可能吗?
You just need to add a view to the tab bar's view hierarchy. 您只需要在标签栏的视图层次结构中添加视图。 Remove it when you're done.
完成后将其删除。
Something like this adds a label view on top of the tab bar's view: 这样的事情会在标签栏视图的顶部添加一个标签视图:
# somewhere in your .m:
UILabel *label;
# later on:
- (void)viewDidLoad
{
[super viewDidLoad];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 140, 44)];
[label setText:@"Hello"];
[self.view addSubview:label];
}
I did it in viewDidLoad
, but you can do it wherever it makes sense to your code. 我是在
viewDidLoad
,但是您可以在对代码有意义的任何地方进行操作。
Then, you can make it disappear with something like this: 然后,您可以通过以下方式使其消失:
# even further along:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[label removeFromSuperview];
}
This will make it disappear whenever any tab is touched. 只要触摸任何选项卡,它就会消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.