How do I make it so that it goes to ChatScreen when I click the "OK" button?
.alert(
Text("enter chat screen"),
isPresented: $showConfirmationPopup
) {
Button("Cancel", role: .cancel) {}
Button("OK") {
print("enter screen tapped")
// some operations
}
} message: {
Text("enter chat screen?")
}
I tried to wrap the "OK" button in NavigationLink but it didn't work. I tried to add NavigationLink(destination: ChatScreen()) {} under the ok button but it didn't work either.
You should replace the
Buttonwith aNavigationLink. And the view with the alert needs to be inside aNavigationStack.Here is a standalone example to show it working: