使用 ESTabBarController 添加标签栏

Add a tab bar using ESTabBarController

我想在我的应用程序中添加一个标签栏。我添加了标签栏的页面不断刷新自己。我的 customAnimateRemindStyle3() 函数不断被调用。我该怎么办?

class MainTableViewController: UITableViewController, UITabBarControllerDelegate {
  override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)     
       self.present(AppDelegate.customAnimateRemindStyle3(implies: false), animated: false, completion: nil)   
  }
}

class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegate {
static func customAnimateRemindStyle3(implies: Bool) -> ExampleNavigationController {
        let tabBarController = ESTabBarController()
        if let tabBar = tabBarController.tabBar as? ESTabBar {
            tabBar.itemCustomPositioning = .fillIncludeSeparator
        }
        let v1 = MainTableViewController()
        let v2 = MainTableViewController()
        let v3 = MainTableViewController()
        let v4 = MainTableViewController()
        let v5 = MainTableViewController()

        v1.tabBarItem = ESTabBarItem.init(ExampleAnimateTipsContentView3(), title: nil, image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v2.tabBarItem = ESTabBarItem.init(ExampleAnimateTipsContentView3(), title: nil, image: UIImage(named: "find"), selectedImage: UIImage(named: "find_1"))
        v3.tabBarItem = ESTabBarItem.init(ExampleAnimateTipsContentView3.init(specialWithAutoImplies: implies), title: nil, image: UIImage(named: "photo_big"), selectedImage: UIImage(named: "photo_big_1"))
        v4.tabBarItem = ESTabBarItem.init(ExampleAnimateTipsContentView3(), title: nil, image: UIImage(named: "favor"), selectedImage: UIImage(named: "favor_1"))
        v5.tabBarItem = ESTabBarItem.init(ExampleAnimateTipsContentView3(), title: nil, image: UIImage(named: "me"), selectedImage: UIImage(named: "me_1"))

        tabBarController.viewControllers = [v1, v2, v3, v4, v5]

        if let tabBarItem = v2.tabBarItem as? ESTabBarItem {
            DispatchQueue.main.asyncAfter(deadline: .now() + 2 ) {
                tabBarItem.badgeValue = "1"
            }
        }

        let navigationController = ExampleNavigationController.init(rootViewController: tabBarController)
        return navigationController
    }
}

This is happening because you are presenting a new ExampleNavigationController that contains MainTableViewController on ViewWillAppear of MainTableViewController

简而言之,您是 递归地 一遍又一遍地调用 MainTableViewController

您在这里可以做的是

首先删除这一行形成ViewWillAppear

self.present(AppDelegate.customAnimateRemindStyle3(implies: false), animated: false, completion: nil)

然后在 App-delegate present 中 TabBarController

开头
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    self.window = UIWindow(frame: UIScreen.main.bounds)

    self.window?.rootViewController = AppDelegate.customAnimateRemindStyle3(implies: false), animated: false, completion: nil)
    self.window?.makeKeyAndVisible()

    return true
}