3

I have a tab bar controller and I have added five view controllers in it like this:

class InfluencerMainTabBarController: UITabBarController {
override func viewDidLoad() {
    super.viewDidLoad()

    let findWorkVC = UINavigationController.init(rootViewController: InfluencerFindWorkVC.instantiate(fromAppStoryboard: .Influencer))
    findWorkVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_home"), tag: 0)

    let inboxVC = UINavigationController.init(rootViewController: InfluencerInboxVC.instantiate(fromAppStoryboard: .Inbox))
    inboxVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_inbox"), tag: 1)

    let workDiaryVC = UINavigationController.init(rootViewController: InfluencerWorkDiaryVC.instantiate(fromAppStoryboard: .Influencer))
    workDiaryVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_work"), tag: 2)

    let notificationsVC = InfluencerNotificationsVC.instantiate(fromAppStoryboard: .Influencer)
    notificationsVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_notification"), tag: 3)

    let accountVC = InfluencerProfileVC.instantiate(fromAppStoryboard: .Influencer)
    accountVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_profile"), tag: 4)

    let tabBarList = [findWorkVC, inboxVC, workDiaryVC, notificationsVC, accountVC]

    viewControllers = tabBarList

    self.tabBar.tintColor = UIColor.appPurpleColor
    self.tabBar.barTintColor = UIColor.white
}
}

Problem is my first controller, which is findWorkVC, its viewWillAppear is getting called but when I click on any other view controller, their viewWillAppear are not getting called.

It is working fine pre iOS 13 devices but on iOS 13 its not just getting called and also the height of navigation bar is lesser than iOS 12's navigation bar height, you can see the title in navigation bar is just overlapping the status bar text.

enter image description here

Noor Ali Butt
  • 798
  • 8
  • 24

2 Answers2

2

I created a new project and tested out everything, view controllers with tabs, everything was working there but not in my project so I started looking for the things which were different in my project than a newly created project.

Turns out, it was the root view controller. I was setting root view controller like this with animation

let controller = InfluencerMainTabBarController.instantiate(fromAppStoryboard: .Main)

UIView.transition(from: self.view, to: controller.view, duration: 0.6, options: [.transitionFlipFromTop], completion: { completed in
     UIApplication.shared.keyWindow?.rootViewController = controller
})

So I simply presented the view controller with modalPresentationStyle = .fullScreen without animation and everything worked.

let controller = InfluencerMainTabBarController.instantiate(fromAppStoryboard: .Main)
controller.modalPresentationStyle = .fullScreen
DispatchQueue.main.async { UIApplication.shared.keyWindow?.rootViewController = controller }

Now I only have to look for how to set root view controller with animation. :|

Noor Ali Butt
  • 798
  • 8
  • 24
0

If your presentation style is not the new default by Apple (sheet), than just set the presentation style for all your ViewControllers (NavigationController included) to FullScreen. This way the viewWillAppear method will be called again for every VC.

cseh_17
  • 194
  • 2
  • 10