使用ESTabBarController添加标签栏

问题描述 投票:-1回答:1

我想在我的应用程序中添加一个标签栏。我添加标签栏的页面不断刷新自己。我的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
    }
}
swift uitabbarcontroller
1个回答
2
投票

发生这种情况是因为你在ExampleNavigationControllerMainTableViewController上展示了一个新的ViewWillAppear,其中包含MainTableViewController

简单地说,你是递归地呼吁一遍又一遍地呈现MainTableViewController

你在这里可以做的是

首先从ViewWillAppear中删除此行

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

然后在App-delegate呈现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
}

© www.soinside.com 2019 - 2024. All rights reserved.