,因爲我們知道,實現PageTabBarController,我們需要在AppDelegate.swift插入這些代碼:Cosmicmind/Material:我如何在不使用AppDelegate.swift的情況下實現PageTabBarController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
let viewControllers = [MatchDetailViewController(),ListPlayersViewController(),ChatViewController()]
window = UIWindow(frame: Device.bounds)
window!.rootViewController = MatchViewController(viewControllers: viewControllers, selectedIndex: 0)
window!.makeKeyAndVisible()
}
現在,我需要使用PageTabBarController當我想打開詳細爲我的比賽數據。我的問題是,如何在不插入AppDelegate.swift中的代碼的情況下實現它,因爲它將打開我的MatchViewController(從PageTabBarController擴展)用於第一次啓動應用程序。
我曾嘗試這個代碼,但它會造成崩潰,並指了指我AppDelegate.swift
class MatchViewController: PageTabBarController {
var window: UIWindow?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
open override func prepare() {
super.prepare()
let viewControllers = [MatchDetailViewController(),ListPlayersViewController(),ChatViewController()]
//1st try: Crash
window = UIWindow(frame: Device.bounds)
window!.rootViewController = MatchViewController(viewControllers: viewControllers, selectedIndex: 0)
window!.makeKeyAndVisible()
//2nd try: error
self.rootViewController = MatchViewController(viewControllers: viewControllers, selectedIndex: 0)
//3rd try: crash
self.viewControllers = viewControllers
delegate = self
preparePageTabBar()
}
fileprivate func preparePageTabBar() {
pageTabBar.lineColor = Color.blue.base
pageTabBar.dividerColor = Color.blueGrey.lighten5
pageTabBarAlignment = PageTabBarAlignment.top
pageTabBar.lineAlignment = TabBarLineAlignment.bottom
}
}
extension MatchViewController: PageTabBarControllerDelegate {
func pageTabBarController(_ pageTabBarController: PageTabBarController, didTransitionTo viewController: UIViewController) {
}
}
感謝,我真的很熟悉添加的UIViewController作爲一個孩子的控制器,但我必須找出另一種替代方案來實現的TabBar(使用的CollectionView )用於容器視圖的標題和UIPageViewController –
只要您有解決方案,就可以了。我目前正在重構PageTabBarController,所以如果你有任何進一步的建議或問題,請讓我知道,謝謝:) – CosmicMind