0

Brief: I have 4 controllers embedded in UINavigationController, who are then used as tabs in UITabbarController, (No storyboards and .xib's) through code.

Previously I was using Xcode 10.3, there were no issues but after I changed to 11.3 these issues came up.

Issues:

  1. when I tap on the tabs, viewWillAppear, and viewDidAppear on the controllers are not getting called.

  2. similar issue with navigation controller Xcode 11 UINavigationController Bar problems

  3. Pop back (pressing back button) from any controller after navigating to it is not getting animated.

Code TabbarController:

final class TabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.viewControllers = [
            TabBarItems.home.tabController,
            TabBarItems.search.tabController,
            TabBarItems.cart.tabController,
            TabBarItems.account.tabController
        ]

        self.tabBar.isTranslucent = false
    }
}

extension TabBarController {
    enum TabBarItems {
        case home
        case search
        case cart
        case account

        var title: String {
            switch self {

            case .home:
                return "Home"
            case .search:
                return "Search"
            case .cart:
                return "Bag"
            case .account:
                return "Account"
            }
        }

        var tabController: UINavigationController {
            switch self {

            case .home:
                return createNavController(viewController: HomeController(), title: self.title, imageName: Assets.home.rawValue)
            case .search:
                return createNavController(viewController: UIViewController(), title: self.title, imageName: Assets.search.rawValue)
            case .cart:
                return createNavController(viewController: BagController(), title: self.title, imageName: Assets.shoppingBag.rawValue)
            case .account:
                return createNavController(viewController: AccountController(), title: self.title, imageName: Assets.account.rawValue)
            }
        }

        private func createNavController(viewController: UIViewController, title: String, imageName: String) -> UINavigationController {
            let navController = UINavigationController(rootViewController: viewController)
            viewController.view.backgroundColor = .white
            navController.tabBarItem.title = title
            navController.tabBarItem.image = imageName.image
            return navController
        }
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Subhajit Halder
  • 1,427
  • 13
  • 21
  • Can you post a [mcve]? I just did a quick test, using your code, and both `viewWillAppear` and `viewDidAppear` are called each time I select a tab. – DonMag Jan 03 '20 at 13:11
  • @DonMag Ok I will. – Subhajit Halder Jan 03 '20 at 13:17
  • @SubhajitHalder I've checked your code with Xcode 11.3 (11C29) and as @DonMag wrote - both `viewWillAppear` and `viewDidAppear` are called each time I select a tab – Vadim Nikolaev Jan 03 '20 at 13:32
  • @SubhajitHalder -- here is what I used as a test: https://gist.github.com/DonMag/b110502a78c50749f2c73ca31d281508 -- the only change I made was to use image names (instead of your `Assets.name.rawValue`). – DonMag Jan 03 '20 at 13:35
  • @DonMag I will check the gist and let me do the code in 10.3 and try to run it using 11.3, if I do face similar issue I will let you know, but as you said you did it using 11.3 and it is working, may be some other issue is there, will check and let you know. – Subhajit Halder Jan 03 '20 at 14:01
  • @VadimNikolaev will check and let you know – Subhajit Halder Jan 03 '20 at 14:02

1 Answers1

0

The issue was with a project created in XCode 10.3 and trying to run it out of the box in XCode 11+.

As prior to iOS 13/ XCode11, the apps starting point was AppDelegate but now in Xcode 11+, SceneDelegate shared some of the responsibility. i.e. the window configuration should be done in scene(:willConnectTo:) function.

I forgot to add SceneDelegate.swift and Info.plist key for that.

Thanks @DonMag for helping me out.

Subhajit Halder
  • 1,427
  • 13
  • 21