如何使用StoryBoard在UITabBarController中设置选定的选项卡? [英] How do I set selected tab in UITabBarController using StoryBoard?

查看:82
本文介绍了如何使用StoryBoard在UITabBarController中设置选定的选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用StoryBoard切换到 UITabBarController 中的某些标签?我尝试过以下代码但没有成功(选项卡未选中):

How can I switch to some tab in UITabBarController using StoryBoard? I have tried the code below but without success (the tab is not selected):

self.tabBar.selectedIndex = 3;

老实说,我使用没有StoryBoard的nib文件,上面的代码在

Honestly I used nib files without StoryBoard and this code above worked fine in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions
          :(NSDictionary *)launchOptions

但现在我无法以编程方式设置选项卡。也许还有另一个与选择标签无关的问题。如何切换标签?

but now I can't set the tab programatically. Maybe there is another problem that is not connected to selecting the tab. How can I switch tabs?

推荐答案

抓住你的 UITabBarController 的实例然后设置 selectedViewController 属性:

Grab your instance of UITabBarController then set the selectedViewController property:

yourTabBarController.selectedViewController=[yourTabBarController.viewControllers objectAtIndex:3];//or whichever index you want

这篇关于如何使用StoryBoard在UITabBarController中设置选定的选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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