I got the same and I don't use a search bar. My app can switch between tab control or Navigation Split View and I debug by putting a toggle. Up until now I've used the NavigationSplitView for my Mac version but I saw the tabview update and decided to try it and my app crashed when pressing a tab and gave me no good warning.
Creating a simple tabview to NavigationSplitView sample code I get the same, with this mentioned error, when tapping a tabview option. Code:
struct ContentView: View {
@State var isCompact: Bool = false
var body: some View {
VStack {
if isCompact {
EntryTab()
} else {
EntrySidebar()
}
Toggle(isOn: $isCompact, label: {
Text(isCompact ? "On" : "Off")
})
.padding(.horizontal, 20)
.padding(.bottom, 20)
}
}
}
public struct tabControl: Identifiable, Hashable, Sendable {
public static func == (lhs: tabControl, rhs: tabControl) -> Bool {
lhs.id < rhs.id
}
public var id: Int // Tab Number
public var displayName: String
public init(id: Int, displayName: String) {
self.id = id
self.displayName = displayName
}
}
struct EntryTab: View {
let entryTabs = [
tabControl(id: 0, displayName: "row 0"),
tabControl(id: 1, displayName: "row 1"),
tabControl(id: 2, displayName: "row 2"),
tabControl(id: 3, displayName: "row 3")
]
@State private var selectedTab: Int = 0
var body: some View {
TabView(selection: $selectedTab) {
ForEach(entryTabs) { tabCtrl in
NavigationSplitView {
Text("Selected tab is \(selectedTab)")
} detail: {
Text("Choose item from sidebar... in future this would be content")
}
.tabItem {
Text(tabCtrl.displayName)
}
.tag(tabCtrl.id)
}
}
}
}
struct EntrySidebar: View {
@State private var selectedTabID: Int?
let entryTabs = [
tabControl(id: 0, displayName: "row 0"),
tabControl(id: 1, displayName: "row 1"),
tabControl(id: 2, displayName: "row 2"),
tabControl(id: 3, displayName: "row 3")
]
var body: some View {
NavigationSplitView(sidebar: {
List(entryTabs, id:\.id, selection: $selectedTabID) { thisItem in
Text(thisItem.displayName)
}
}, content: {
Text("Hi selected tab: \(String(describing: selectedTabID))")
}, detail: {
Text("Choose item from sidebar... in future this would be content")
})
.onAppear() {
// Set the selected tab
selectedTabID = 1
}
}
}