iOS 16 beta | UINavigationController / UINavigationBar title does not appear after being updated

Overview

The UINavigationController / UINavigationBar title text no longer appears when updating a view controller's title property programatically.

Example

Given a view controller that is hosted within a UINavigationController:

final class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // start out with no title
    }

    private func updateTitle() {
        // update the title later on ...
        title = "Hello"
    }
}

In this case the title label remains blank after calling updateTitle() instead of updating to "Hello!".

Details

  • This only happens if the title starts out as nil or empty string
  • Triggering a layout (e.g. rotating the screen) will restore the title
  • Manually calling navigationController?.navigationBar.setNeedsLayout() restores the title
  • Inspecting the view hierarchy, it appears the UILabel within the navigation bar has an alpha of 0.0 which is why it appears blank even after setting the title, it's not till after triggering a layout the alpha is reset to 1.0
(lldb) po navigationController?.navigationBar.perform(Selector("recursiveDescription"))
...
<_UINavigationBarTitleControl: 0x7f84f5f11560; frame = (172.333 10; 45.3333 23); layer = <CALayer: 0x6000039e89a0>>

  | <UILabel: 0x7f84f5f12000; frame = (0 0; 45.3333 23); text = 'Hello'; alpha = 0; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer: 0x600001ab4410>>

   | <UIView: 0x7f84d5f0fbc0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x6000039d7780>>

Environment

This only occurs when building with Xcode 14 beta 6 (14A5294g) and running on iOS 16 beta.

Notes

I was curious if anyone else encountered this?

We initially missed this as many of our view controller had some default titles set but there were a few where titles get set asynchronously after viewDidLoad which surfaced this issue.

I wonder if some of the changes related to SwiftUI listed in the release notes may have accidentally changed the behaviour:

By default, a navigation bar only renders if it has content to display. If a navigation bar has no title, toolbar items, or search content, it’s automatically hidden. Use the navigationBarHidden(_:) or the new .toolbar(.visible) modifier to explicitly show an empty navigation bar. (84996257)

I've filed a feedback FB11379313 with a sample project that reproduces this issue.

Thanks

Post not yet marked as solved Up vote post of k.wridan Down vote post of k.wridan
5.9k views

Replies

I have encountered same issue

  • x2 I encountered same issue (alpha:0), on XCode 14 RC + simulator....... can confirm setting title="xyz" initially vs empty "", make bug go-away/working correctly again.

Add a Comment

Sadly it seems the bug is still present when building with Xcode 14 rc (14A309).

The current known workarounds:

  • Ensure there's an initial non empty title
  • Manually invoke navigationController?.navigationBar.setNeedsLayout() after updating the title
  • I have encountered same issue on iPhone SE 2020 iOS16, solution of k.wridan helped me.

Add a Comment

This bug appears to be iOS 16-specific - a build from Xcode 14 installed on an iOS 15.3.1 device does not exhibit this issue.

Same issue for me: solved with k.wridan solution at the moment.

I had the same problem. However, iOS 16.1 solved it.

The invisible character U+FEFF may be of use here, as a space does not work.

Good to hear that iOS 16.1 solves it. However, a funny thing:

My app in the App Store, which was built with Xcode 13.4.1, runs correctly on the device under iOS 16.0. But when I build the same sources using Xcode 14 and run it under iOS 16.0 (on the device), it fails exactly as described above, and k.wridan's solution works there. Same for iOS 16.0.2, which is the latest atm. I presume 16.1 is in beta.

Makes me wonder if a later version of Xcode is also required.

My app is actually in Xamarin, but same deal.

Same issue for App: iOS16.0 Xcode14.0 but iOS16.0.3 solved it.