fortmarek / SwipeViewController

SwipeViewController is a Swift modification of RKSwipeBetweenViewControllers - navigate between pages / ViewControllers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can use it with Storyboard and UITabBarController

cougarwww opened this issue · comments

if I want use Storyboard and UITabBarController, I can not change AppDelegate function didFinishLaunchingWithOptions rootViewController, I try to this code, but it not work.

`class mySwipeView: SwipeViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let VC1 = MaybeViewController()
    VC1.view.backgroundColor = UIColor.blueColor()
    VC1.title = "mybe"
    let VC2 = TodayViewController()
    VC2.view.backgroundColor = UIColor(red: 0.70, green: 0.23, blue: 0.92, alpha: 1.0)
    VC2.title = "today"
    let VC3 = HistoryViewController()
    VC3.view.backgroundColor = UIColor(red: 0.17, green: 0.70, blue: 0.27, alpha: 1.0)
    VC3.title = "history"

    setViewControllerArray([VC1, VC2, VC3])
    setFirstViewController(0)
    setSelectionBar(80, height: 3, color: UIColor(red: 0.23, green: 0.55, blue: 0.92, alpha: 1.0))
    setButtonsWithSelectedColor(UIFont.systemFontOfSize(18), color: UIColor.blackColor(), selectedColor: UIColor(red: 0.23, green: 0.55, blue: 0.92, alpha: 1.0))
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

class Hiall: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    let pageController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
    let navigationController = mySwipeView(rootViewController: pageController)

// navigationController.loadViewIfNeeded()
//
// self.view.addSubview(navigationController.view)

    self.addChildViewController(navigationController)

}

}
`

First of all, sorry that it has taken me so much time to get to you. In didFinishLaunchingWithOptions try the code below

let pageController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
        let navigationController = ViewController(rootViewController: pageController)
/*Now we don't make navigationController the rootViewController but we use it in tabBarController.setViewControllers() function
We also have to set the navigationController's tabBarItem
*/
        navigationController.tabBarItem = UITabBarItem(title: "HEY", image: nil, selectedImage: nil)

//Random viewController just as a placeholder
        let vc = UIViewController()
        vc.tabBarItem = UITabBarItem(title: "TITLE", image: nil, selectedImage: nil)

        let tabBarController = UITabBarController()
        tabBarController.setViewControllers([navigationController, vc], animated: true)


        self.window?.rootViewController = tabBarController
        self.window?.makeKeyAndVisible()

Please, tell me if this worked for you.

EDIT:

As for the storyboard (kind of forgot about that):
Why can't you change didFinishLaunchingWithOptions function? You can have all the viewControllers in storyboard, you just need to set the rootViewController in code.

I will close the issue for now, if I get a response that the problem preserves, I'll reopen it.