Swift 3标签栏禁用标签 [英] Swift 3 tab bar disable tab

查看:87
本文介绍了Swift 3标签栏禁用标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含5个标签的标签栏.我们想要创建一个功能,使我们可以通过编程方式启用/禁用选项卡栏的某些选项卡,以使用户无法单击它.

I have created a tab bar with 5 tabs. we want to create a feature that we can enable/disable some tabs of tab bar programmatically so that user will not able to click on it.

我们使用了默认的标签栏控制器,而我们使用的是swift3.有人知道如何管理这些东西吗?

We have used default tab bar controller and we are using swift 3. Does anyone have an idea how to manage this stuff?

我尝试了很多方法,但是似乎无法限制用户单击选项卡.

I have tried many ways but it seems that it's not possible to restrict the user to click on the tab.

请让我知道是否有人面对并解决了这个问题.

Please let me know if anyone has faced and solved this issue.

推荐答案

let tabBarControllerItems = self.tabBarController?.tabBar.items

if let tabArray = tabBarControllerItems {
    tabBarItem1 = tabArray[0]
    tabBarItem2 = tabArray[1]

    tabBarItem1.isEnabled = false
    tabBarItem2.isEnabled = false    
}

只需将上面的代码块放在供初学者使用的viewDidLoad()方法中,别忘了创建tabBarItem变量

Just put the block of code above in the viewDidLoad() method for starters and don't forget to create the tabBarItem variables

这篇关于Swift 3标签栏禁用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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