I have a huge Problem with SwiftUi. The "Backbutton" in a really Simple NavigationView Hierarchy disappears on the third View. If I go one view further, the Backbutton is there again and I can go back.
I searched like 3 Hours but only found this SwiftUI: Back button disappears when clicked on NavigationLink
Obviously this doesn't solve my Problem.
Thanks for any Help!
I found another workaround for who doesn't want to use a deprecated method.
Just add in your .toolbar
this ToolBarItem
:
.toolbar {
// ... other toolbar items
ToolbarItem(placement: .navigationBarLeading) {
Text("")
}
}
Another solution which seems to be working on Xcode 12.4
:
ToolbarItem(placement: .navigationBarLeading) {
HStack {}
}
In case you want to make your code cleaner
/// A ToolbarItem wrapper to work around the back button disappearance bug in SwiftUI 2.
struct NavbarBackButtonDisappearanceWorkaroundItem: ToolbarContent {
var body: some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Color.clear
}
}
}
Use as follows:
.toolbar {
NavbarBackButtonDisappearanceWorkaroundItem()
SomeOtherUsefulItem()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With