I am trying to add a toolbar item "Done" button on my view and it works fine when I don't switch views within a TabView. When I do switch do a different tabItem the "Done" button disappears. I'm providing a simple example here that demonstrates. How can I resolve this issue?
struct ContentView: View {
@State private var text: Double = 0
var body: some View {
TabView {
NavigationStack {
VStack {
Text("View 1")
TextField("", value: $text, format: .currency(code: "USD").precision(.fractionLength(0)))
.textFieldStyle(.roundedBorder)
Button {UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
} label: {
Text("Dismiss")
}
}
.padding()
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("Done") {
print("Done")
}
}
}
}
.tabItem { Label("View 1", systemImage: "house") }
NavigationStack {
Text("View 2")
}
.tabItem { Label("View 2", systemImage: "figure.walk") }
}
}
}