I Pushed a PctView into NavigationView. When I change a binding value in PctView, it is dismissing itself. Please help understanding this behaviour.
import SwiftUI
struct Technology: Identifiable {
var id: UUID = UUID()
var techName: String
var completionPct: Float = 0.0
}
struct parentView: View {
@State var technology = Technology(techName: "Front End")
@State var tempList = [1,2]
var body: some View {
NavigationView {
VStack {
NavigationLink {
ChildView(technology: $technology)
} label: {
Text(technology.techName)
}
}.navigationTitle(technology.techName)
}
}
}
struct ChildView: View {
@Binding var technology: Technology
var body: some View {
VStack {
Text(technology.techName)
NavigationLink {
PctView(completionPct: $technology.completionPct)
} label: {
Text("Go To Pct Changing View")
}.navigationTitle(technology.techName)
}
}
}
struct PctView: View {
@Binding var completionPct: Float
var body: some View {
Button("Change Pct") {
completionPct = completionPct + 0.1
}.navigationTitle("Pct View")
}
}
struct Test: PreviewProvider {
static var previews: some View {
parentView()
}
}
You can't have 2 levels of
NavigationLinkwithNavigationViewby default. You need to either set the second link to.isDetail(false)or you can make SwiftUI generate aUINavigationControllerinstead of aUISplitViewControllerby using.navigationStyle(.stack). Best only do this if you are not targeting iPad.