Having the next scenario right here. Principally I need to have dynamic quantity of tab bar objects relying on a scenario. Within the offered instance under when the button is tapped it’ll add yet one more tab in the midst of the array (index 1) the place beforehand stayed case .5
. The issue I’m having is that when the brand new .three
tab exhibits and I click on on it the app crashes with the next error:
"Structure requested for seen navigation bar, <SwiftUI.UIKitNavigationBar: 0x100710c50; baseClass = UINavigationBar; body = (0 24; 1024 102); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0x600000c63390>; layer = <CALayer: 0x60000026e5a0>> delegate=0x110016200, when the highest merchandise belongs to a special navigation bar. topItem = <UINavigationItem: 0x100712790> title="Whats up" type=navigator leftItemsSupplementBackButton largeTitleDisplayMode=all the time, navigation bar = <SwiftUI.UIKitNavigationBar: 0x10951dc00; baseClass = UINavigationBar; body = (0 24; 1024 102); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0x600000c8b960>; layer = <CALayer: 0x60000028ad60>> delegate=0x10f052800, probably from a shopper try to nest wrapped navigation controllers."
The attention-grabbing half about it, is that it solely occurs on iOS 17+ and never on 16. The small POC I get the error on:
class ContentViewModel: ObservableObject {
@Printed var tabs: [Tab] = [.one, .five]
static var shared = ContentViewModel()
}
struct ContentView: View {
@State var choice: Tab = .one
@StateObject var vm = ContentViewModel.shared
var physique: some View {
TabView(choice: $choice) {
ForEach(vm.tabs, id: .self) { tab in
tab
.tag(tab)
.tabItem {
Textual content(tab.rawValue)
}
}
}
}
}
enum Tab: String {
case one = "One"
case three = "Three"
case 5 = "5"
}
extension Tab: View {
var physique: some View {
NavigationStack {
swap self {
case .one:
Textual content("One")
case .three:
Textual content("Three")
case .5:
Button("Change") {
if ContentViewModel.shared.tabs.rely == 3 {
ContentViewModel.shared.tabs.removeSubrange(1...1)
} else {
ContentViewModel.shared.tabs.insert(.three, at: 1)
}
}
.navigationTitle("Whats up")
}
}
}
}