'Dismiss a SwiftUI navigation view on an iPad in portrait mode when a selection is made
On my SwiftUI app, I have a navigation view on the left side on an iPad in portrait mode, and after I make a selection, I want the navigation view to disappear. It does this for the first time, but subsequent times, I have to click on the view on the right for it to disappear. I have no idea how to make this happen consistently.
Here is a very simple chunk of code that demonstrates the problem. When you run it and click "< Back", it will show the menu of options on the left, and when you first click an option, it disappears. The next time you click the "< Back" at the top left and then click another selection, it will continue to show that list until you click the pane on the right. It does update the pane on the right with your choice each time, as it should.
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("You selected option 1")) {
Text("Option 1")
}
NavigationLink(destination: Text("You selected option 2")) {
Text("Option 2")
}
NavigationLink(destination: Text("You selected option 3")) {
Text("Option 3")
}
}
}
}
}
Thanks for your help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
