I am trying to create a custom navigation bar in my navigation controller that persists through each view after the initial navigation controller. I set up the navigation bar in a custom UINavigationController class, and I am trying to inherit the navigation controller's properties in my UIViewController custom class (the first View Controller after the nav controller)
Here is the syntax I am using, where HomePageViewController is my UIViewController that I want to inherit the Navigation Bar and numberInput is a UITextField in my HomePageViewController:
SearchNavigationController.swift
class SearchNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Set up custom navigation bar
}
HomePageViewController.swift
class HomePageViewController: SearchNavigationController, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var numberInput: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
numberInput.delegate = self
}
However, when my app calls numberInput.delegate = self, I get the error: fatal error: unexpectedly found nil while unwrapping an Optional value.
But when I replace SearchNavigationController with UIViewController it works.
UINavigationControlleris a "collection" ofUIViewControllers. If yourUINavigationControlleris already customised, all theUIViewControllers that are pushed in or pop off of your custom NavCon, will have the same navigation bar.