Update to Xcode 11.3.1 - navigationBar and half of the Views disappear after storyboard refactoring

357 Views Asked by At

Using Xcode 11.3.1, Simulator11.3.1, iPhoneX, Swift5.1.3, iOS13.3,

I am wondering why half of my app suddenly disappears !! Could it be the update to Xcode 11.3.1 ???

The following shows a screenshot of the Xcode Debug View Hierarchy.

The left side is what the iPhone 11 Pro Simulator shows and the right side is the Debug View Hierarchy:

Clearly there are many more objects in the view hierarchy (such as the round buttons at the bottom) that are not shown on the Simulator (and also not on a physical iPhoneX). Also the NavigationBar is missing completely !!!!

The blue highlighted object is a custom navigationBar (consisting of a stackView). This worked before but not since the Xcode update. I am really not believing this. What could go wrong here ??

If it is not the Xcode-update, then my refactoring of the storyboard could also be a cause of this view-losses.

Before my refactoring, the VC at question was a ChildViewController of another ViewController. Now, it is the entry point of the App. Could this change bring the view-losses ? I want to see a NavigationController with largeTitle. But there is no NavigationController whatsoever now!

enter image description here

Here is the code that sets up the navigationBar:

override func viewDidLoad() {
    // set up navigationItem and navigationController look and feeel
    navigationItem.largeTitleDisplayMode = .always
    navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    navigationController?.set_iOS12_lookAndFeel()
    navigationItem.title = "bluub"
}

And the needed NavigationController extension:

import UIKit

extension UINavigationController {

    func set_iOS12_lookAndFeel() {
        if #available(iOS 13.0, *) {
            self.keep_iOS12_lookAndFeel()
        } else {
            let attrLargeTitle = AppConstants.FontAttributes.NavBar_LargeTitleTextAttributes
            self.navigationBar.largeTitleTextAttributes = attrLargeTitle
            let attrTitle = AppConstants.FontAttributes.NavBar_TitleTextAttributes
            self.navigationBar.titleTextAttributes = attrTitle
        }
    }

    private func keep_iOS12_lookAndFeel() {
        if #available(iOS 13.0, *) {
            let navBarAppearance = UINavigationBarAppearance()
            navBarAppearance.configureWithDefaultBackground()
            navBarAppearance.backgroundEffect = .init(style: .systemThickMaterialDark)
            navBarAppearance.titleTextAttributes = AppConstants.FontAttributes.NavBar_TitleTextAttributes
            navBarAppearance.largeTitleTextAttributes = AppConstants.FontAttributes.NavBar_LargeTitleTextAttributes
            navBarAppearance.buttonAppearance.normal.titleTextAttributes = AppConstants.FontAttributes.NavBar_ButtonAppearance_Normal
            navBarAppearance.doneButtonAppearance.normal.titleTextAttributes = AppConstants.FontAttributes.NavBar_Done_ButtonAppearance_Normal
            self.navigationBar.standardAppearance = navBarAppearance
            self.navigationBar.scrollEdgeAppearance = navBarAppearance
        }
    }
}

.

---------------- more findings -----------------------------

After another storyboard refactoring, I could bring back the round menu buttons. However, the largeTitle-NavigationBar is still completely missing.

Frankly, the latest refactoring did not introduce any new constraints or other storyboard settings as before. The fact that I kicked out the NavigationController and replaced it by an identical new one, plus, re-assigned one or the other constraint of the menu-button-View, did bring the bottom menu back alive. As far as I can tell, no difference to the previous storyboard was introduced.

It is very annoying why a storyboard needs to be redrawn basically to render correctly. Something seems corrupt here as for the Xcode functionality with storyboard !

But lets leave this talk.

My remaining question:

How can I bring back a missing NavigationBar ?????????

enter image description here

.

---------------- another finding -----------------------------

If I reassign the "first-entry-ViewController" to the old ViewController that eventually adds the Menu-button-ViewController as a ChildViewController --> then everything works!

If I assign the "first-entry-ViewController" to be the Menu-button-ViewController directly, then the NavigationBar disappears !

Here is the overview:

enter image description here

1

There are 1 best solutions below

1
iKK On

I finally found a solution.

It indeed had to do with my login-architecture of this app.

The fact that only by setting the "first-entry-ViewController" as the old-Main-ViewController made a difference:

This old-Main-ViewController (that eventually adds the Menu-button-ViewController as its Child) did have the following line in its viewWillAppear method:

navigationController?.setNavigationBarHidden(true, animated: animated)

Its intention was actually to never show the navigationBar of its own. But instead load a ChildViewController that itself shows a navigationBar of its own.

The strange thing with storyboard: Even tough setting the Menu-button-ViewController as first-entry does somehow still consider the navigationController-hiding mechanism of the previous first-entry setting. This seems a bug to me inside storyboard. I would assume that visible navigationBar is the default behaviour. But having set it once to be hidden keeps it hidden, even tough the hiding-command is no longer executed. Anyway, very strange behaviour.

By eliminiting that line - or better - by adding it "with hidden = false" inside the Menu-Button-ViewController, makes the NavigationBar being shown again !!!

My learning is to keep an eye on all navigationController actions or mutations throughout the entire App hierarchy. The fact that a single ViewController might mutate something on its navigationController might not be enough. You have to check event parent-ViewControllers or segue-parents as well. And most annoying, applying a different first-entry to a VC does require you to overwrite default behaviours of your views to make sure your views are shown !