In my project, I create a UITabbarController using the storyboard. Later, I change the images and title of the individual tabbar items in the code. This works with the new tabbar controller from iOS 18, with one exception: If the iPad switches to a horizontally compact mode and thereby triggers the old tabbar (at the bottom of the screen), the images and titles from the storyboard appear there, not the values changed in the code. Am I doing something wrong or is this a bug?
Problem with new UITabbarController on IOS 18 beta (Bug?)
It’s hard to tell what’s happening without seeing a code sample. Could you file a developer feedback through the Feedback Assistant and attach a sample project that reproduces this issue to help us investigate the issue?
As described above, I create the UITabBarController with the storyboard and name the first item "Storyboard".
Then I change the name to "Code" with the following code:
theTabBarController.tabBar.items[0].title = "Code"
// By the way, this doesn’t work at all ... ?!
theTabBarController.tabs[0].title = "Code"
The new tab bar is displayed correctly:
But as soon as I reduce the window on the iPad and the compact size is triggered, the "old" tab bar appears at the bottom of the window:
Instead of "Code", the first item still shows "Storyboard". I could imagine that the problem has something to do with the fact that I create the UITabBarController using the storyboard. But that should still work, right?
(The tab bar is displayed correctly on the iPhone, by the way. So for me the problem is limited to the iPad only.)
Likely, the content is reloaded from storyboard.
- Did it work OK in iPadOS 17 ?
- where do you set set theTabBarController.tabBar.items[0].title
Did you try to set theTabBarController.tabBar.items[0].title for instance in
override func viewWillLayoutSubviews() {
Yes, it worked in iPadOS 17. And yes, I changed the title of the tabbar item exactly there (viewWillLayoutSubviews) …
Here is a mini project that shows the bug (BETA 3).
https://file.io/fkrDXwYfgyAs
Screenshot:
class RotatingTabBarControllerSwift: UITabBarController {
private var myAppDel = AppDelegate()
// MARK: - Methoden
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.updateTabBarItems()
}
// MARK: - Helper Methoden
func updateTabBarItems() {
if let items = self.tabBar.items {
print("# UPDATED")
let symbolConfig = UIImage.SymbolConfiguration(weight: .light)
items[0].image = UIImage(systemName: "house.fill", withConfiguration: symbolConfig)
items[1].image = UIImage(systemName: "person.fill", withConfiguration: symbolConfig)
items[0].title = "Code 1"
items[1].title = "Code 2"
self.tabs[0].title = "Code 3"
self.tabs[1].title = "Code 4"
// Tabbar in compact style still shows "Storyboard 1" and "Plus" image ... it should show "Code 1" (or even better "Code 3") and a "House" image
}
}
}