1

I'm making a transition in the TabBarController by using the TabBarControllerDelegate method shouldSelectViewController. I'm getting the following warning

Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x1804dcf0>.

I believe that this is because the line where I'm calling viewWillAppear(true) (marked with *** below) on the destination ViewController (this to smooth the transition to the new controller).

I saw this question and this other question that are similar but not exactly the same. I think i should tell the current View Controller on screen that he will be removed (as this warning started to appear when added the marked line), but I'm not sure how.

func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {

    let controllerIndex: Int = find( (self.viewControllers as! [UIViewController]), viewController)!

    if(controllerIndex == tabBarController.selectedIndex) {
        return false
    }

    // Get the views
    let fromView: UIView = tabBarController.selectedViewController!.view
    let toView: UIView = (tabBarController.viewControllers as! [UIViewController])[controllerIndex].view

***
    // Tell the destination view controller know it will appear on screen
    (tabBarController.viewControllers as! [UIViewController])[controllerIndex].viewWillAppear(true)
***

    let viewSize = fromView.frame
    let scrollRight = controllerIndex > tabBarController.selectedIndex;

    // Add the to view to the tab bar view.
    fromView.superview?.addSubview(toView)


    // Position it off screen.
    let screenWidth = UIScreen.mainScreen().bounds.size.width
    toView.frame = CGRectMake(
        scrollRight ? screenWidth : -screenWidth,
        viewSize.origin.y,
        screenWidth,
        viewSize.size.height
    )

    UIView.animateWithDuration(0.2, animations: { () -> Void in
        fromView.frame = CGRectMake(
            scrollRight ? -screenWidth : screenWidth,
            viewSize.origin.y,
            screenWidth,
            viewSize.size.height
        )

        toView.frame = CGRectMake(
            0,
            viewSize.origin.y,
            screenWidth,
            viewSize.size.height
        )
    }) { (finished) -> Void in
        if(finished) {
            fromView.removeFromSuperview()
            tabBarController.selectedIndex = controllerIndex
        }
    }

    return false;
}
Community
  • 1
  • 1
Fdo
  • 1,053
  • 4
  • 15
  • 38

0 Answers0