在 SwiftUI 中,我有一个包含 6 个以上选项卡的 TabView。当我尝试导航到更多选项卡时,更多选项卡将不起作用。我将如何使更多选项卡工作?我现在可以使用所有其他选项卡进行导航,但无法使用更多选项卡进行导航。
谢谢。
下面是创建 TabView 的代码:
struct ContentView: View {
@State private var selection = 0
@State private var resetNavigationID = UUID()
var body: some View {
let selectable = Binding(
get: { self.selection },
set: { self.selection = $0
self.resetNavigationID = UUID()
})
return TabView(selection: selectable) {
self.SearchTabView().navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Image(systemName: "magnifyingglass")
Text("Search")
}.tag(0)
self.PostJobTabView().navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Image(systemName: "person.crop.rectangle")
Text("Post a Job")
}.tag(1)
self.JobHistoryTabView().navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Image(systemName: "person.3")
Text("My Jobs History")
}.tag(2)
self.SignInTabView().navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Image(systemName: "lock.icloud")
Text("Sign In")
}.tag(3)
}
private func SearchTabView() -> some View {
NavigationView {
VStack {
SearchView().navigationBarTitle("Search", displayMode: .inline)
}
}.id(resetNavigationID)
}
private func PostJobTabView() -> some View {
NavigationView {
VStack {
PostJobView().navigationBarTitle("Post a job", displayMode: .inline)
}
}
}
private func JobHistoryTabView() -> some View {
NavigationView {
VStack {
MyJobsHistoryView().navigationBarTitle("My Jobs History", displayMode: .inline)
}
}
}
private func SignInTabView() -> some View {
NavigationView {
VStack {
SignInView().navigationBarTitle("Sign In", displayMode: .inline)
}
}
}
}