SwiftUi:tabviews和导航视图当TabViews不是主页时的问题

发布于 2025-02-04 07:14:32 字数 1149 浏览 1 评论 0原文

下午好,

我在应用程序上有一个问题。第一次启动该应用程序时,用户将显示登录页面并注册页面(没有TabView),一旦登录,它们就会将其定向到带有不同部分的TabView(主页,聊天等)。 )。

我遇到的主要问题是,从登录视图更改为tabview时,设置的导航列表仅是家庭视图的导航词,而更改为其他选项卡时,标题不会更改。我该如何解决这个问题,其他应用程序如何处理?

谢谢。

文件loginview

import SwiftUI

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

文件tabview

import Swift UI

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

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

文件homeview

import SwiftUI

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

文件chatsview

import SwiftUI

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

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")
   }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与他有关 2025-02-11 07:14:32
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)
}

}

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)
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文