iosswift:如何将选项卡项的徽章值设置为选项卡栏控制器的所有选项卡项

时间:2022-08-26 21:39:54

I have a Tab Bar controller with 4 tabs. I am displaying different set of data on each tab in table view. I need to set the badge values of each tab bar item with the number of rows present in the respective tab.

我有一个带4个标签的标签栏控制器。我正在表视图中的每个选项卡上显示不同的数据集。我需要设置每个选项卡栏项的徽章值,并在相应的选项卡中显示行数。

When the tab bar controller is loaded, the first tab is the default tab shown to the user.

当加载选项卡栏控制器时,第一个选项卡是显示给用户的默认选项卡。

Now, how can I set the badge values of all other 3 tabs with the number of records??

现在,我如何用记录的数量设置其他3个选项卡的徽章值?

1 个解决方案

#1


1  

let num = "your num need show" print(num) let tabArray = self.tabBarController?.tabBar.items as NSArray! let chatTab = tabArray.objectAtIndex(3) as! UITabBarItem if num == 0{ chatTab.badgeValue = nil }else{ chatTab.badgeValue = "\(num)" }

让num = "your num need show" print(num)让tabArray = self。tabbarcontroller ?。tabbar。项目NSArray !让chatTab = tabArray.objectAtIndex(3) as!UITabBarItem if num = 0。badgeValue = nil。badgeValue = " \(num)"}

#1


1  

let num = "your num need show" print(num) let tabArray = self.tabBarController?.tabBar.items as NSArray! let chatTab = tabArray.objectAtIndex(3) as! UITabBarItem if num == 0{ chatTab.badgeValue = nil }else{ chatTab.badgeValue = "\(num)" }

让num = "your num need show" print(num)让tabArray = self。tabbarcontroller ?。tabbar。项目NSArray !让chatTab = tabArray.objectAtIndex(3) as!UITabBarItem if num = 0。badgeValue = nil。badgeValue = " \(num)"}