2

I am wrapping my navigaton view inside a tab view. but when I load the app, my navigation view is always going to its next page by default. How can I stop this ? I spent so much time but could not figure it out.

here is my view

ZStack {
    Color.red
        .edgesIgnoringSafeArea(.all)
    VStack {
                TabView(selection:$selectedTab) {
                    NavigationView {
                        VStack {
                            Text("Hello")
                        }
                            .edgesIgnoringSafeArea(.all)
                    }
                    .tag(1)
                    VStack {
                        Text("Two")
                    }
                    .tag(2)

        }
        .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
    }
}

FirstView is a navigation view like this

NavigationView {
    VStack {
        ...
    }
    .sheet(isPresented: $myForm, onDismiss:{  }) {
        NewFormView(...)
    }
    .navigationBarHidden(true)
}

It appears like this enter image description here

ILuvProgramming
  • 121
  • 1
  • 11
  • You have a back button, that means you must be using navigationLink in your code somewhere, the code you shared doesn’t have that information. Please share more details regarding your code. – Tushar Sharma Jun 05 '21 at 19:17
  • thanks. I will edit the code – ILuvProgramming Jun 05 '21 at 19:55
  • I found out that this line is causing that ```.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))``` any idea how I can fix this ? I want to use a custom tab bar – ILuvProgramming Jun 05 '21 at 20:02
  • 1
    I think it’s a bug in SWIFTUI. I found a alternative way to achieve what I wanted. If anyone is curious https://medium.com/@sai.kante/how-to-style-tabviews-tab-bar-in-swiftui-f05932da64c5 – ILuvProgramming Jun 05 '21 at 23:23

0 Answers0