0

I have three storyboards in my project. There is a main and two separate workflow storyboards. Each storyboard is embedded in its own navigation controller.

Since I have broken up the storyboards into workflows I have to programmatically add each workflow to the tab bar. This is working correctly.

My issue occurs when I try and push a view (within a workflow) onto the workflows navigation controller. It seems that the navigation controller for a workflow is never being used. I verified this by changing the navigation bar color for each workflow.

I have tried two options, each set up on a workflow.

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

    let mainStoryboard = UIStoryboard(name: "Workflow 1", bundle: nil)
    let actionItemStoryboard = UIStoryboard(name: "Workflow 2", bundle: nil)

    let workflow1Controller = mainStoryboard.instantiateViewController(withIdentifier: "navigationController1")
    let workflow1TabItem = UITabBarItem(title: "Item 1", image: nil, selectedImage: nil)
    workflow1Controller.tabBarItem = workflow1TabItem

    let workflow2Controller = actionItemStoryboard.instantiateViewController(withIdentifier: "workflow2")
    let workflow2TabItem = UITabBarItem(title: "Item 2", image: nil, selectedImage: nil)
    workflow2Controller.tabBarItem = workflow2TabItem

    self.viewControllers = [workflow1Controller, workflow2Controller]
}

Option 1

Setting the tab view controller to point to the navigation controller (pretty sure this is incorrect but was a test I did). This displays the views how I want but doesn't show the navigation item (back button).

Error pushing navigation controller


Option 2

Setting the tab view controller to point to the list view (see screen shots below). This displays the back button but upon clicking on the cell the last view is displayed "over" the tabs.

Error pushing list view


Main Storyboard enter image description here

Workflow 1 Storyboard Workflow 1 Storyboard

Workflow 2 Storyboard Workflow 2 Storyboard

sargturner
  • 540
  • 2
  • 18
  • You don't need a UINavigationController embedded in your UITabBarController. It's fine to have them on your tabs. Then each tab has it's own navigation. – Mark McCorkle Dec 19 '16 at 19:59
  • Please see the new "Main storyboard" image. I made my example here too vague trying to simplify. I actually need the navigation controller there as well. – sargturner Dec 19 '16 at 20:05
  • 1
    I don't think putting a UITabBarController inside a navigation controller is a supported option. See https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html#//apple_ref/doc/uid/TP40011313-CH3-SW2 for a list of the four ways to use a tab bar controller. (Yes, you can attempt to do anything but it's better not to fight against UI standards.) – Phillip Mills Dec 19 '16 at 20:24
  • @PhillipMills I think you're right. I did some searching on UITabBarController inside a UINavigationController and seems like that is against apple guidelines. However you should be able to add a view controller and place a tab bar on that view controller and accomplish what I am trying to do. http://stackoverflow.com/questions/576764/tab-bar-controller-inside-a-navigation-controller-or-sharing-a-navigation-root – sargturner Dec 19 '16 at 20:36
  • You can use storyboard references in Interface Builder to embed your two workflows directly into the tab bar controller, but I agree with Philip, it isnt a recommended solution to embed a tab bar controller in a navigation controller. Your segue from the root table to the tab bar controller should probably be a modal show rather than a navigation push and you can get rid of the root navigation controller – Paulw11 Dec 19 '16 at 20:58
  • @Paulw11 my only issue with a modal show is I need to be able to get back to that list. Think of my case here as a list of projects. Then the tabs represent workflows within a project. I need to be able to have the user back up and switch projects. Hence my attempt to have a root navigation controller. – sargturner Dec 19 '16 at 21:04
  • As soon as you dismiss the modal you will be back at the tableview. The root navigation controller isn't providing any benefit – Paulw11 Dec 19 '16 at 22:04
  • Are you just wanting to pop back to a specific point? This is where Unwind Segues (Exit) comes in handy. Just unwind to a specific point and you can set the tabBar's selectedIndex to a different tab if that's what you're trying to achieve. – Mark McCorkle Dec 20 '16 at 20:19

1 Answers1

0

In order to solve this I ended up doing the following:

  • Remove the navigation controllers from the workflows
  • Create a "MockTabController" (just a UIViewController with a UITabBar placed on the bottom of the view)

Now that I have a UIViewController with a UITabBar I can have each workflow view extend this view instead of a UIViewController and thus a tab bar is consistent throughout my app (where I want it).

For instances where the workflow has a UITableViewController I simply embed the UITableViewController inside a ViewController as a child view. The ViewController then extends my MockTabController and the result is a TableViewController with a tab bar that doesn't need any modifications to work.

In order to simplify the navigating throughout the app, I simply reset the navigation stack back to the beginning of the tab controller. Clicking a tab bar item unwinds all the workflow and then pushes the start of a new workflow.

sargturner
  • 540
  • 2
  • 18