navigationBarBackButtonHidden(_ hidesBackButton: Bool) -> some View
But it still shows the back button and I want to remove the back function when clicked.
The . navigationBarBackButtonHidden(true) will hide the back button.
Use navigationBarHidden(_:) to hide the navigation bar. This modifier only takes effect when this view is inside of and visible within a NavigationView .
Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.
Maybe:
.navigationBarBackButtonHidden(true)
I tried placing .navigationBarBackButtonHidden(true)
in a few different places. This is the behaviour I observed.
struct PageOne: View {
var body: some View {
NavigationView {
VStack{
NavigationLink(destination: PageTwo()){
Text("Go to Page Two")
}
}
}
}
}
// Hide from page 2 -> page 1
struct PageTwo: View {
var body: some View {
VStack{
NavigationLink(destination: PageThree()){
Text("Go to Page Three")
}.navigationBarBackButtonHidden(true)
}
}
}
// Hide from page 3 -> page 2 (Same behaviour as Kheldar's answer above)
struct PageTwo: View {
var body: some View {
VStack{
NavigationLink(destination: PageThree().navigationBarBackButtonHidden(true)){
Text("Go to Page Three")
}
}
}
}
struct PageThree: View {
var body: some View {
Text("Hello!")
}
}
This is the solution, but it doesn't work on Xcode 11 beta 4:
struct LiveView: View {
var body: some View {
NavigationView {
NavigationLink(destination: ButtonView()) {
Text("Next screen")
}
}
}
}
struct ButtonView: View {
@State var navigationBarBackButtonHidden = true
var body: some View {
Button("Show back") {
self.navigationBarBackButtonHidden = false
}.navigationBarBackButtonHidden(navigationBarBackButtonHidden)
}
}
There is also navigationBarHidden
which doesn't work on the iPhone, but it works perfectly on watchOS.
I encountered a situation where I couldn't get the .navigationBarBackButtonHidden(true)
to work until I placed it on the View that I embedded within the NavigationLink
itself.
NavigationLink(destination:MyView(stuff: aStuff, onDismiss: {})) {
HStack {
Text(aStuff.interestingText)
}
} // <- used to set it here, doesn't work for me
with:
struct MyView: View {
var aStuff: Stuff
var onDismiss: () -> Void
var body: some View {
VStack(alignment: .leading) {
Button(action: self.onDismiss) {
Image(systemName: "chevron.left.circle")
}
CoolAnimatedStuffDisplayer(stuff: aStuff)
}
.navigationBarBackButtonHidden(true) // <--- works here
}
}
Using via a navigationLink
NavigationLink(destination: SomePage().navigationBarBackButtonHidden(true), tag: 1, selection: $selection) {
//..
}
The .navigationBarBackButtonHidden(true)
will hide the back button.
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