gpt4 book ai didi

ios - TabBarItem 角标(Badge)值未显示

转载 作者:行者123 更新时间:2023-11-30 13:56:16 31 4
gpt4 key购买 nike

我写了这段代码,但它似乎不起作用,我不知道为什么,TabBarItem是正确的,但角标(Badge)没有显示。

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = mainStoryboard.instantiateViewControllerWithIdentifier("TabBar") as! UITabBarController
let tabArray = tabBarController.tabBar.items as NSArray!
var chatItem = tabArray.objectAtIndex(3) as! UITabBarItem
chatItem.badgeValue = "1"

最佳答案

当你更新值时,你必须重新加载 tabBarController,所以这样做:

let tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("TabBar") as! TabsViewController // Your tabor controller
tabBarController.selectedIndex = 2 // Whatever your selected index

let tabArray = tabBarController.tabBar.items as NSArray!
let chatItem = tabArray.objectAtIndex(3) as! UITabBarItem
chatItem.badgeValue = "1"
var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBarController

关于ios - TabBarItem 角标(Badge)值未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33581581/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com