简体   繁体   中英

SwiftUI TabView Issue

I'm building an app and i'm a fairly beginner in SwiftUI, so this is the problem I have. I need a landing page which shows first and I've created a view for it you can check it out.

     struct LandingView: View {
var body: some View {   
    NavigationView{
    VStack(alignment: .center){
        Image("exxxlogo")
        Spacer()
        Text("Welcome")
            .font(.system(size: 38))
            .fontWeight(.bold)
            .padding(.horizontal, 40)
            .multilineTextAlignment(.center)
            .foregroundColor(Color.white)
        Text("Click below to continue to the app")
            .font(.system(size: 16))
             .padding(.horizontal, 20)
            .multilineTextAlignment(.center)
            .foregroundColor(Color.white)
            .padding(.bottom, 35)
        NavigationLink(destination: HomeView()){
            Text("CONTINUE ")
                  .frame(width: 250, height: 50, alignment: .center)
                  .background(Color.red)
                  .foregroundColor(Color.white)
        }
        
    }
    
        .background(
            
            Image("backgroundlanding")
                
                .frame(maxWidth: .infinity,maxHeight: .infinity)
                .aspectRatio(contentMode: .fill)
                                .edgesIgnoringSafeArea(.top)
                .edgesIgnoringSafeArea(.bottom)
               
    )
}

And I've also created the views for the tabview to redirect them to so Home,Shop, etc I've done this to my Contentview

    TabView {
        
       
               HomeView()
                .tabItem{
                    Image(systemName: "house")
                    Text("Home")
                }
        
                GamesView()
                    .tabItem{
                        Image(systemName: "gamecontroller")
                        Text("Games")
        
                
                    }
        
        ShopView()
         .tabItem{
             Image(systemName: "bag")
             Text("Shop")
            }
        
        MoreView()
            .tabItem{
                Image(systemName: "gear")
                Text("More")
        
            }.accentColor(.red)

And changed the windowgroup to landingview in the main app.swift file so it pops up first. But the issue is when you click on the button in landingview, navigationlink redirects you to the homeview but there is no tabviews underneath just blank

You said that your second code example is from ContentView . If you want to show the TabView that you have in that ContentView , then your NavigationLink should point to ContentView , not HomeView .

NavigationLink(destination: ContentView()) {
            Text("CONTINUE ")
                  .frame(width: 250, height: 50, alignment: .center)
                  .background(Color.red)
                  .foregroundColor(Color.white)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM