以编程方式选择一个标签栏项目(不使用 UITabBarController) [英] Select a tab bar item programmatically (not using UITabBarController)

查看:24
本文介绍了以编程方式选择一个标签栏项目(不使用 UITabBarController)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个派生自 UIViewControler(而不是 UITabBarController)的视图.在这个视图中,我添加了一个带有多个标签栏项目的标签栏.我使用了 UITabBarDelegate 来允许视图在用户点击每个标签栏项目时做一些事情.

I have a view derived from UIViewControler (not UITabBarController). In this view I added a tab bar with several tab bar items. I used the UITabBarDelegate to allow the view to do something when users tap on each tab bar item.

class MyViewController: UIViewController, UITabBarDelegate {

    func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
        // do something
    }
}

我的问题是我们如何在第一次加载视图时以编程方式选择第一个标签栏项目?请注意,我还希望第一个选项卡项也处于活动"状态.

My question is how we can programmatically select the first tab bar item when the view is first loaded? Note that I would want the first tab item to be in "active" state also.

再说一次,我没有使用 UITabBarController

Again, I'm not using UITabBarController

谢谢

推荐答案

[tabBar setSelectedItem: [tabBar.items objectAtIndex:0]];

我认为很快:

tabBar.selectedItem = tabBar.items![0] as UITabBarItem

这篇关于以编程方式选择一个标签栏项目(不使用 UITabBarController)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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