So I'm making this app and realised I have two back buttons. From the very first view, when I enter the second view and enter the third view from the second view, I have two back buttons, the very first page back button and the second back button.
How do I get rid of the very first back button?
This is the code for the second view. If the first view's code is quite long so if needed, please ask me
Thank you
import SwiftUI
struct MovieView: View {
@Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>
var body: some View {
NavigationView{
VStack{
List{
//Your Name Block
NavigationLink {
YourNameView()
} label: {
VStack{
Image("your name")
.resizable()
.aspectRatio(contentMode: .fill)
.cornerRadius(20)
Text("Your Name")
.fontWeight(.bold)
.font(.system(size:20))
}
.padding()
.background(Image("beige"))
}
//notting hill block
NavigationLink {
NottingHillView()
} label: {
VStack{
Image("notting hill")
.resizable()
.aspectRatio(contentMode: .fill)
.cornerRadius(20)
Text("Notting Hill")
.fontWeight(.bold)
.font(.system(size:20))
} .background(Image("beige"))
.padding()
}
//notting hill block
NavigationLink {
//Love_OtherDrugsView()
} label: {
VStack{
Image("love and other drugs")
.resizable()
.aspectRatio(contentMode: .fill)
.cornerRadius(20)
Text("Love & Other Drugs")
.fontWeight(.bold)
.font(.system(size:20))
}
.padding()
.background(Image("beige"))
}
}
.navigationTitle("Movies")
Spacer()
Button {
} label: {
VStack{
Image(systemName: "plus.circle.fill")
.resizable()
.scaledToFit()
.frame(width:24, height:24)
.foregroundColor(Color.red)
Text("Add movie")
.foregroundColor(Color.red)
}
}
}
}
}
struct MovieView_Previews: PreviewProvider {
static var previews: some View {
MovieView()
}
}
}
@yh29 , the problem is that you are using nested NavigationView
s. If you remove the NavigationView
in your MovieView struct, the second back button will go away. Once you have one NavigationView
, any view that you have navigated to within this will also be encapsulated in the NavigationView
.