Chapter 14. Has anyone tried to add a UITabBarController before the new UINavigationController?


In this chapter we see how we can insert a UINavigationController for out UITableView.
I am trying to expand the program and insert a UITabBarController before but the debugger stops at the following code in AppDelegate - func application(_ application: UIApplication, didFinishLaunchingWithOptions):

//Create an ItemStore
let itemStore = ItemStore()

let navController = window!.rootViewController as! UINavigationController
let itemsController = navController.topViewController as! ItemsViewController
itemsController.itemStore = itemStore

The error message I get is that it can’t cast the UITabBarViewController (the window!) to type of UINavigationController. I have tried to fix this problem but then I am having all other type of problems.

Any assistance would be much appreciated.


are you able to post more of your code here?


Hi, I managed to make the code work. the problem was that I was calling for the DB before it was actually created. All sorted now.