I keep receiving errors in my debugger saying:
2020-07-18 15:59:07.256759-0400 ThePillowApp[22009:7205609] Warning: Attempt to present <SwiftUI.PlatformAlertController: 0x1070aba00> on <TtGC7SwiftUI19UIHostingControllerVVS_22_VariadicView_Children7Element: 0x106b978e0> whose view is not in the window hierarchy!
A snapshot of my code:
##First View
class User: ObservableObject {
@Published var test = false
}
struct RegisterView: View {
@EnvironmentObject var user: User
var body: some View {
NavigationView{
...
HStack{
NavigationLink(destination: AccountView().navigationBarTitle("")
.navigationBarHidden(true), isActive: self.$user.test) {
Text("").foregroundColor(.black).font(Font.custom("DiariaPro-Light", size: 12))}
Button(action: {self.user.test=true}) {
Text("Don't have an account?")
.font(Font.custom("DiariaPro-Light", size: 12))
.foregroundColor(.black)
}}}
##Second View
struct AccountView: View {
@EnvironmentObject var user: User
@State private var alertMessage = "Error message"
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var body: some View {
NavigationView{
...
HStack{
Button(action: {
DispatchQueue.main.async {
self.user.test=false
self.presentationMode.wrappedValue.dismiss()
}
}) {
Text("Already have an account?")
.font(Font.custom("DiariaPro-Light", size: 12))
.foregroundColor(.black)
}}
Basically, what I want to do is on the first view, if you don't have your account, you click the button which takes you to the sign up page. On the sign up page (#second view), you can create an account. The problem I am running into is that it appears that after I dismiss the second view (via self.user.test=false or self.presentationMode.wrappedValue.dismiss()) and return to the first view, the second view is still presenting itself.
I know this because I installed alerts on both views, and when I triggered the alert on the first view, there was no error about "the platform alert controller" trying to present on the hosting controller. On the second view, that error was there (I presume because I navigated to the second view from the first view). BUT when I go from the first to the second and back to the first, that warning remains, which is the one about presenting (even after i dismissed).