2

我确实有一个带有侧边栏的应用程序,用于放置我的主导航。当我从侧边栏导航时,我的 DetailView 应显示在侧边栏旁边。但是,当我想从 MainView 导航到 DetailView 时,它不起作用。该视图仅显示为覆盖。

有什么方法可以从侧边栏和主视图本身在我的主窗口中导航?

import SwiftUI
@main
struct NavigationTestApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                ContentView()
                MainView()
            }
        }
    }
}
struct ContentView: View {
    var body: some View {
        List {
            NavigationLink(
                destination: DetailView(),
                label: {
                    Text("DetailView")
                })
        }
        .listStyle(SidebarListStyle())
    }
}
struct MainView: View {
    var body: some View {
        NavigationLink(
            destination: DetailView(),
            label: {
                Text("Navigate") /* Navigation does not work properly here*/
            })
            .frame(width: 1280, height: 720)
    }
}
struct DetailView: View {
    var body: some View {
        Text("DetailView")
            .frame(width: 1280, height: 720)
    }
}
4

0 回答 0