I am working a lot with SwiftUI recently and encountered a problem when controlling NavigationLinks from outside the NavigationView with a @State.
The Problem: As soon as I move to the Third Screen, I get the Error Message above. And also when moving between the Third and Fourth Screen, thee behavior is changing more or less to Random. *For example when finishing Screen 3, it comes again instead of Screen 4 and more.*
My Solution for this Problem: I was browsing for possible Solutions and found one Solution that seems to does the Job
My Question: Although this Line of Code does the Job, removes the Error Messages and prevents this Random Behavior, I could't find an Explanation of what causes the Error and why this is able to solve it. So if you have an Idea, please share it with me.
Thanks for your Help.
What Do I do? I am using a Button outside a NavigationView to control a hierarchy of NavigationLinks inside the NavigationView via @State Properties which the Button is manipulating.Error Message: [Assert] displayModeButtonItem is internally managed and not exposed for DoubleColumn style. Returning an empty, disconnected UIBarButtonItem to fulfill the non-null contract
Code Block swift struct OnboardingRoot: View { @State var didCompletFirstView: Bool = false @State var didCompleteSecondView: Bool = false @State var didCompleteThirdView: Bool = false var body: some View { ZStack { NavigationView { Text("View 1") .background( NavigationLink(destination: Text("View 2"), isActive: $didCompleteFirstView) { EmptyView() } ) /* This Hierarchy contains a Total of 4 Screens !!! */ } VStack { Spacer() Button(action: { print("Calls a Function that updates the States accordingly.") }) { CustomButton(text: "Start") } } } } }
The Problem: As soon as I move to the Third Screen, I get the Error Message above. And also when moving between the Third and Fourth Screen, thee behavior is changing more or less to Random. *For example when finishing Screen 3, it comes again instead of Screen 4 and more.*
My Solution for this Problem: I was browsing for possible Solutions and found one Solution that seems to does the Job
Code Block swift .navigationViewStyle(StackNavigationViewStyle())
My Question: Although this Line of Code does the Job, removes the Error Messages and prevents this Random Behavior, I could't find an Explanation of what causes the Error and why this is able to solve it. So if you have an Idea, please share it with me.
Thanks for your Help.