I am having issues with pushing a view in SwiftUI by using a NavigationLink.
Currently I have it set up so that a binding boolean is set to "true" depending on whether a login was successful or not. However, when I run the code, the view is not pushed despite the boolean being successfully changed.
I am using Swift 5 and developing on WatchOS 6.2, which does NOT require the NavigationLink to be nested in a NavigationView since it's not supported.
import SwiftUI
struct Login: View {
@State var pushErrorView = false
@State var pushActivityView = false
var body: some View {
VStack{
Button(action:
{
self.login()
}) {
Text("Log In")
}
NavigationLink(destination: PopupMessage(message: "Login Error"), isActive: self.$pushErrorView) {
EmptyView()
}.hidden()
NavigationLink(destination: ActivityView(), isActive: self.$pushActivityView) {
EmptyView()
}.hidden()
}
}
private func login(){
if loginSuccess() {
self.pushActivityView = true
}
else {
self.pushErrorView = true
}
}
}
.hidden()for your NavigationLinks. If they only haveEmptyView()as a body they won't be visible.