I'm getting a strange crash from pretty normal navigation on my SwiftUI app
I have a simple tab view :
struct FFTabView: View {
var body: some View {
TabView {
LibraryView2()
}
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
.navigationBarTitle("", displayMode: .inline)
}
}
// MARK: -
struct LibraryView2: View {
var body: some View {
VStack {
NavigationLink(destination: Foo()) {
Text("go to foo")
}
}
.tabItem {
Image(systemName: "square.grid.2x2.fill")
Text("Skill Library")
}
}
}
struct Foo: View {
var body: some View {
Text("foo view")
}
}
When I go back via my nav bar, from Foo
I get a crash: Tried to pop to a view controller that doesn't exist
Any idea what's going on here? I can't find anything related to this and SwiftUI so figured I'd post. Thanks
ContentView -> View1 -> View2 And from View2 you want to pop to the Root view.
NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.
Although you didn't specify, I assume your FFTabView
is wrapped in a NavigationView
somewhere.
Ultimately, then, your view hierarchy looks like
NavigationView {
TabView {
NavigationLink {
...
}
}
}
If you restructure your view hierarchy so it's like
TabView {
NavigationView {
NavigationLink {
...
}
}
}
The crash doesn't happen.
Edit: I have confirmed that it is related to the regression/bug discussed in this answer, introduced in Xcode 11.2. Your original code works fine in Xcode 11.1.
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