I'm pretty sure I'm writing this code correctly, and the keyboard toolbar shows up in the simulator. When I test on-device, though, the keyboard toolbar doesn't show up. I know this issue has been around intermittently since swiftui was released, but I figured it would have been fixed by now.
I did submit another feedback request regarding this issue, but maybe I'm just writing the view in the wrong way to get this to function? I'm thinking that might be the case -- in another project I can get the toolbar to appear once, but after switching from one textfield to another it stops appearing.
This is my attempt to get it to work in a simple demo project (excerpted from the original):
// Content View
NavigationStack {
List {
// ...
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Image(systemName: "plus")
}
}
}
}
.sheet(item: $presentedItem) { item in
NavigationStack {
ItemView(item: item)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("Cancel") {
self.modelContext.delete(item)
self.presentedItem = nil
}
}
ToolbarItem(placement: .topBarTrailing) {
Button("Save") {
self.presentedItem = nil
}
}
}
.navigationTitle("Item")
}
}
// Item View
ScrollView {
VStack {
TextField("Title", text: $title, axis: .vertical)
.focused($focus, equals: TextFieldFocus.title)
}
}
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
HStack {
Spacer()
Button("Done") {
self.focus = nil
print("done tapped")
}
}
}
}
.navigationTitle("ItemView")