1
votes

I'm completely stumped on this problem.

I have an app whose view controllers are mostly made on the storyboard. However, there are a few that are made entirely with code (programmatically).

The entry point for my app is a TabBarController that feeds in to many different Navigation Controllers, each with its own UIViewController.

Here is a visual representation: enter image description here

I have no problem navigating to any of the proper view controllers (who are represented in the storyboard) using the Tab Bar Items. However, when I choose a Tab Bar Item that does not have a direct segue on the storyboard - because its UIViewController is built entirely through code - I cannot segue to the proper class.

I've added a *.swift class to the NavigationController that has a ViewDidLoad() function. This function is NEVER called when I choose the appropriate Tab Bar Item. The strange part is that there is a single Navigation Controller that is connected to a UIViewController (displayed in the storyboard) and has a *.swift file attached to it. Its ViewDidLoad() does get called when the proper Tab Bar Item is selected. I've tried to attach multiple *.swift files (all inheriting from UINavigationController) but I cannot get a single one to call the appropriate ViewDidLoad() function.

Edit: As you can see in the image, the bottom left Navigation Controller does not have a segue extending from it. However, there is a class attached to it and inside its ViewDidLoad() function is where the segue takes place

class WeaponsNavController: UINavigationController
{

    override func viewDidLoad()
    {          
         self.navigationController?.pushViewController(WeaponsTableVC(), animated: true)
    }

}

As you can see, I'm trying to connect to the WeaponsTableVC() which is a view controller created entirely through code. However, this class does not seem to get called at all despite being directly connected to the Navigation Controller in the storyboard.

1
Can you show the code where you add the programatic view controller to your tab bar controller? Also which navigation controller are you referring to at the start of the second paragraph? One made programatically, or one in the storyboard without a root view controller?Mark

1 Answers

1
votes

If the view controller does not have an associated nib file, this method creates a plain UIView object instead. If you do not provide a nib file when instantiating the view controller, UIViewController calls it's loadView() method which creates a plain UIView object and assigns it to its view property.

// Assuming TestViewController is the view to load
let viewController = TestViewController()
navigationController?.pushViewController(viewController, animated: true)

Hope this helps.