Swift Segue删除tabBarItem.badgeValue

Swift Segue删除tabBarItem.badgeValue,swift,uinavigationcontroller,uitabbarcontroller,segue,Swift,Uinavigationcontroller,Uitabbarcontroller,Segue,我有一个自定义的tabbar控制器,在其中一个tabbar项目上有一个红色的圆形计数器。第一个选项卡项显示摘要视图控制器。第二个选项卡栏项目显示了嵌入导航控制器中的菜单,选项卡栏计数器可以正常工作,但从摘要视图控制器返回时除外。然后计数器消失了。我已尝试在customTabBarController中加载计数器: import UIKit class CustomTabBarController: UITabBarController { override func viewDidA

我有一个自定义的
tabbar控制器
,在其中一个
tabbar项目上有一个红色的圆形计数器。第一个
选项卡项
显示摘要视图控制器。第二个
选项卡栏项目
显示了嵌入
导航控制器中的菜单
选项卡栏计数器
可以正常工作,但从摘要视图控制器返回时除外。然后计数器消失了。我已尝试在
customTabBarController
中加载计数器:

import UIKit

class CustomTabBarController: UITabBarController {

    override func viewDidAppear(_ animated: Bool) {
        if tabBarCounter != 0
        {
            let vc = self.tabBarController?.viewControllers?.last
            vc?.tabBarItem.badgeValue = "\(tabBarCounter)"
            vc?.tabBarItem.badgeColor = UIColor.red
        }
    }
}    
情节提要的屏幕转储。(底部的
ViewController
就是我遇到问题的.Segue highlited)

如果您是子类化的
UITabBarController
,您可以直接设置tabBarItem属性,并且不要忘记在ViewDidDisplay方法中调用super
覆盖func ViewDidDisplay(uuu动画:Bool){super.ViewDidDisplay(动画)tabBarItem.badgeValue=“value”tabBarItem.badgeColor=.red}
完美!这就成功了