On iPhone Duo, if a tab bar item's title is set to an empty string while the device is in landscape, setting a non-empty title again after rotating back to portrait doesn't display it. The title stays missing.
Filled in FB25015689
Repro:
import UIKit
@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let config = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
config.delegateClass = SceneDelegate.self
return config
}
}
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = scene as? UIWindowScene else { return }
let tab = TitleViewController()
tab.tabBarItem = UITabBarItem(tabBarSystemItem: .favorites, tag: 0)
let tabBarController = UITabBarController()
tabBarController.viewControllers = [tab]
let window = UIWindow(windowScene: windowScene)
window.rootViewController = tabBarController
self.window = window
window.makeKeyAndVisible()
}
}
final class TitleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
let hide = UIButton(configuration: .bordered(), primaryAction: UIAction(title: "hidden") { [weak self] _ in
self?.setTabTitle("")
})
let show = UIButton(configuration: .bordered(), primaryAction: UIAction(title: "visible") { [weak self] _ in
self?.setTabTitle("Favorites")
})
let stack = UIStackView(arrangedSubviews: [hide, show])
stack.axis = .vertical
stack.spacing = 16
stack.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stack)
NSLayoutConstraint.activate([
stack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
stack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
private func setTabTitle(_ newTitle: String) {
title = newTitle
tabBarItem.title = newTitle
}
}