快速标签栏徽章



我有 2 个UIViewController

1-UIViewControllerUICollectionView。在牢房里,我有UIButtonUILabel.当我按UIButton时,我已经将文本从UILabel保存到UserDefaults数组。(主屏幕(

2-UIViewController

当我启动应用程序时,我想点击单元格中的UIButton并在第二个选项卡栏项上显示带有 array.count 的徽章(例如,我点击 3 个不同的按钮和数组有 3 个计数(

我试图通过类中的协议来做到这一点UICollectionViewCell并将扩展添加到 CollectionView 的UIViewController

在集合中 ViewController 在didSelectItemAtIndexPath或您需要更改的任何代码部分secondViewcontroller标签栏徽章

就这样做

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
if let tabItems = self.tabBarController?.tabBar.items
{
// In this case we want to modify the badge number of the seond tab:
let tabItem = tabItems[1]
tabItem.badgeValue = "1" // set count you need
}
}

最新更新