marcosgriselli / SwipeableTabBarController

UITabBarController with swipe interaction between its tabs.
MIT License
1.54k stars 107 forks source link

Error at first swipe #25

Closed CarloTerracciano closed 7 years ago

CarloTerracciano commented 7 years ago

Hello Marcos, your library is very useful but I have a little problem. When I swipe, for the first time in my tabviewcontroller, to go to another viewcontroller the swipe doesn't work. So, I click on my tab button and then the swipe works well. This is my code:

import UIKit
import SwipeableTabBarController

class TabBarController_Th_Pr: SwipeableTabBarController  { 
override func viewDidLoad() {
        super.viewDidLoad()
        selectedViewController = viewControllers![0]
        setSwipeAnimation(type: SwipeAnimationType.sideBySide)

    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Create Tab one
        tabPractice.structuredString = structuredString
        let tabOneBarItem = UITabBarItem(title: practice, image: UIImage(named: "practice_icon"), selectedImage: UIImage(named: "practice_icon"))
        tabPractice.tabBarItem = tabOneBarItem

        // Create Tab two
        tabTheory.structuredStringTh = structuredStringTh
        let tabTwoBarItem2 = UITabBarItem(title: theory, image: UIImage(named: "theory_icon"), selectedImage: UIImage(named: "theory_icon"))
        tabTheory.tabBarItem = tabTwoBarItem2

        self.viewControllers = [tabPractice, tabTheory]

    }

}

Any mistakes in my code? Thanks in advance for the help.

CarloTerracciano commented 7 years ago

I've solved this issue. I have to initialize my selectedViewController in my viewWillAppear.

royherma commented 6 years ago

Hey, can you explain how you fixed this? Thanks!

marcosgriselli commented 6 years ago

@royherma I think the issue comes from not setting the selectedViewController manually. Setting this will trigger the setup of the swiping gesture.