如何从UIButton切换到Tab Bar项目? [英] How to segue from UIButton to a Tab Bar Item?

查看:111
本文介绍了如何从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项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆