Добавить панель вкладок с помощью ESTabBarController - PullRequest
0 голосов
/ 12 апреля 2019

Я хочу добавить панель вкладок в свое приложение.Страница, к которой я добавил панель вкладок, постоянно обновляется.Моя 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
    }
}

1 Ответ

2 голосов
/ 12 апреля 2019

Это происходит потому, что вы представляете новый ExampleNavigationController, содержащий MainTableViewController на ViewWillAppear из MainTableViewController

Проще говоря, вы рекурсивно звоните, чтобы представлять MainTableViewController снова и снова

Что вы можете сделать здесь, это

Во-первых УДАЛИТЬ эта строка формы ViewWillAppear

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

Тогда в App-делегате присутствует 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
}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...