我有 2 个UIViewController
1-UIViewController
与UICollectionView
。在牢房里,我有UIButton
和UILabel
.当我按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
}
}