0

Good afternoon,

I have a problem on my app with the NavigationViews. When launching the app for the very first time, users are displayed a LogIn and Sign Up page (which does not have a TabView) and once they Log-In they are directed to a TabView with different sections (Home, Chats, etc...).

The main problem that I have is that when changing from the Login view to the TabView,the NavigationTitle that is set is only that of HomeView and when changing to a different tab, the title does not change. How could I solve this problem, how do other apps deal with this?

Thank you.

File LoginView

import SwiftUI

struct LoginView: View {
   var body: some View{
      NavigationView{
         NavigationLink(destination: TabView, label: Text("Login")
      }
   }
} 

File TabView

import Swift UI

struct TabView: View {
   var body: some View{
      TabView {
         HomeView()
            .tabItem{
               //Not relevant code
            }

         ChatView()
            .tabItem{
               //Not relevant code
            }
        }
    }
}

File HomeView

import SwiftUI

struct HomeView: View {
   var body: some View {
      ZStack{
         //Not relevant code
      }
      .navigationBarTitle("Home")
   }
}

File ChatsView

import SwiftUI

struct ChatsView: View {
   var body: some View {
     ZStack{
       //Not relevant code
     }
     .navigationBarTitle("Chats")
   }
}

1 Answer 1

0
struct ContentView: View {

enum Tab {
case homeView
case chatView
}
@State var selecion: Tab = .homeView
@State var title = "House"
var body: some View{
    TabView(selection: $selecion){
        HomeView()
            .tabItem{
                //Not relevant code
                Image(systemName: "house")
            }
            .tag(Tab.homeView)
            .onAppear {
                title = "House"
            }
            
        ChatsView()
            .tabItem{
                //Not relevant code
                Image(systemName: "star")
            }
            .tag(Tab.chatView)
            .onAppear {
                title = "Chat"
            }
    }
    .navigationTitle(title)
}

}

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much for the answer, however, this still does not solve my problem because it creates two NavigationViews and one is set over the other. The LoginView already has a NavigationView, therefore, adding another to each of the tabItem views puts it over the previous one. That's the problem I am trying to solve. Thank you again!
ooo i cant see LoginView. I am sorry
Would you know how to solve that?
i am trying but i cant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.