2
votes

I have prepared 2 views which are signing and also the home view. I tried to pop/hide the signing view after the user signing to the home view.

The problem now is the view is allow the user to click the back button to go back to the login view. I have no idea how to settle this. Can anyone give me some hints?

Here is my navigation code for login:

NavigationLink(destination: HomePageView(), tag: 1, selection: $selection) {
    Button(action: {
        print("Register tapped")
        self.verify()
        self.selection = 1
    }) {
        HStack {
            Text("OK").foregroundColor(Color.white).bold().foregroundColor(.white)
                .frame(width: UIScreen.main.bounds.width - 30, height: UIScreen.main.bounds.height / 12)
                .background(Color.orange)
                .cornerRadius(35.0)
                .font(.headline)
                .padding()
        }
    }
}
2
Why don't you want to hide back button? There are a lot of examples here how to do that.Asperi
Sorry may I know is that a proper way to do so?SAS231
You can do everything which is allowed by public APIAsperi
@Asperi I tried to hide the back button but the navigation bar is still there. And my home view got another navigation view. Cause there is 2 navigation view.SAS231
@pawello2222 but in my home view it contained the tab bar which containing the NavigationView. So what she I do now. That means I got 2 separate part of code Register and also Home.SAS231

2 Answers

1
votes

There should only be one NavigationView per navigation stack. You need to remove all nested NavigationViews except the top one. In your child views you still can modify the top one.

Here is a simple demo:

struct LoginView: View {
    @State private var active: Bool = false

    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: HomeView(), isActive: self.$active) {
                    Text("Register")
                }
            }
            .navigationBarTitle("Login View")
        }
    }
}

struct HomeView: View {
    var body: some View {
        Text("inside home view")
            .navigationBarTitle("Home view")
            .navigationBarBackButtonHidden(true)
    }
}

Tested in Xcode 11.6, iOS 13.6.

0
votes

You seem to need a FullScreenCover rather than another view. this way you'll be able to easily present and dismiss the view only on your demand. for more complete info than what i can explain here, please take a look at Paul Hudson's explanation in his website: https://www.hackingwithswift.com/quick-start/swiftui/how-to-present-a-full-screen-modal-view-using-fullscreencover