I'm a newbie developer. Based on what I've read, in the latest version of Xcode it is possible to add a toolbar item to the keyboard in a straightforward manner:
TextField("Today's weight", text: $weight)
.textFieldStyle(.roundedBorder)
.keyboardType(.decimalPad)
.toolbar {
ToolbarItem(placement: .keyboard) {
Button("Click") {
isKeyBoardActive = false
}
}
}
The app is designed with TabView for navigation rather than a navigation view. Based on this link I assumed that Xcode 13.1 would require a navigation view for this to work, but Xcode 13.2 would not. I've confirmed that my Xcode version is 13.2.1.
I've also tried the code with 'ToolbarItem' and 'ToolbarItemGroup'. When my app is run, no toolbar appears with either variation.
Any help would be greatly appreciated.
Edit: Upon further troubleshooting, I've realised that embedding the TextField in the TabView causes it not to work. If its a standalone view (i.e. not in a TabView) the toolbar item is added as expected. Extracting the TextField to its own subview while within TabView doesn't seem to work either.