0

I am "pushing" a new view using NavigationLink like this:

NavigationLink(destination: SomeView(shown: $isActive)), isActive: $isActive) { ... }

Inside SomeView i can now set shown to false to "pop" back. This works.

However, if show an Alert inside SomeView this no longer works. When showing the alert I also get this error message in the console:

popToViewController:transition: called on <_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_19SidebarStyleContext_ 0x7ffc1e858c00> while an existing transition or presentation is occurring; the navigation stack will not be updated.

What am I doing wrong?

Here's how I am showing the alert inside SomeView:

VStack
{
// ...
}
.alert(isPresented:$showAlert)
{
    Alert(title: Text("Some text"), message: Text("More text"), dismissButton: .default(Text("OK")))
}

I show the alert by setting showAlert to true.

scrrr
  • 5,135
  • 7
  • 42
  • 52

1 Answers1

0

Or do you have/ want to do it your way with the @Binding? Or this method of navigating between the views and option? SwiftUI pop view

If so this code works perfectly fine without any error Tested on iOS 13.6

struct ContentView: View {
    
    
    var body: some View {
        NavigationView() {
            NavigationLink(destination: SomeView()) {
                Text("Go to child")
            }
        }
    }
}


struct SomeView: View {
    
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    @State private var showAlert: Bool = false
    
    var body: some View {
        VStack() {
            
            Text("I'm the child and if you press me an alert is comming up")
                .onTapGesture {
                    self.showAlert.toggle()
                }
            
            Text("Go Back")
                .onTapGesture {
                    self.presentationMode.wrappedValue.dismiss()
                }
            
        }.alert(isPresented: $showAlert)
            {
                Alert(title: Text("Some text"), message: Text("More text"), dismissButton: .default(Text("OK")))
            }
        
    }
}
Simon
  • 1,754
  • 14
  • 32
  • I thought the binding way was the proper way, and someone helps me figure out my problem. But your sample works well, although I do get another warning in the console: TestPushPop[35996:2063035] [UIContextMenuInteraction] Attempting -[UIContextMenuInteraction dismissMenu], when not in an active state. This is a client error most often caused by calling dismiss more than once during a given lifecycle. (<_UIVariableGestureContextMenuInteraction: 0x600003577480>) - not sure if this is a completely different matter. – scrrr Jul 18 '20 at 22:21