如何从UIButton切换到Tab Bar项目?

编程入门 行业动态 更新时间:2024-10-24 18:15:57
本文介绍了如何从UIButton切换到Tab Bar项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带标签栏的应用,其中包含5个标签。我决定使用主屏幕,而不是直接在第一个选项卡中打开应用程序。我的主屏幕将包含一条欢迎信息和5个按钮,可直接转到所需的标签。示例:第4个按钮将转到第4个选项卡。单击一个按钮后,永远不会再看到主屏幕。导航模式将通过标签栏。

I have an app with a tab bar, which contains 5 tabs. I decided to have a "Home screen" instead of opening the app directly in the first tab. My home screen will contain a welcome message AND 5 buttons to segue directly to the wanted tab. Example: the 4th button will go to the 4th tab. After clicking one button, the home screen should never be seen again. The navigation mode will by the tab bar.

我的主页视图控制器5按钮和对标签栏控制器的引用,以通过单击按钮。标签栏控制器( @interface TabBar:UITabBarController< UITabBarControllerDelegate> )控制5个标签启动的屏幕。由于某些原因,我无法获得 [self.tabBarController setSelectedIndex:3]; 上班。我把它放在 - (void)viewDidLoad 中,但它什么也没做。

My Home View Controller 5 buttons and a reference to the Tab Bar Controller, to pass the button clicked. The Tab Bar Controller (@interface TabBar : UITabBarController <UITabBarControllerDelegate>) controls the screen where the 5 tabs starts. For some reasons, I can't get [self.tabBarController setSelectedIndex:3]; to work. I put it in - (void)viewDidLoad, but it does nothing.

任何人都知道为什么setSelectedItem不是没打电话?

Anyone has a clue why setSelectedItem isn't called?

编辑:看看那个问题:

self.tabBarController.selectedIndex = 1; NSLog(@"%i", self.tabBarController.selectedIndex);

在运行时,我得到0作为NSLog的结果...为什么不是setter工作?

At runtime, I get 0 as the result of NSLog... Why isn't the setter working?

推荐答案

您可以自定义segbar到Tab Bar Controller并命名segue(例如使用yourSegueName)。

You can custom segue to the Tab Bar Controller and name the the segue (e.g. with "yourSegueName").

只需在所需的标签页上调用UITabBarController和setSelectedIndex:

Than just call the UITabBarController and setSelectedIndex at the desired tab-page:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"yourSegueName"]){ UITabBarController *destController = [segue destinationViewController]; [destController setSelectedIndex:3]; }

}

更多推荐

如何从UIButton切换到Tab Bar项目?

本文发布于:2023-11-11 23:41:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:切换到   项目   UIButton   Bar   Tab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!