macOS中Sheet内NavigationSplitView缺失导航栏问题求助
方案1:将NavigationSplitView嵌入NavigationStack
在Sheet的内容视图外层包裹NavigationStack,即可让导航标题和栏项正常渲染:
struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() .frame(width:800, height:800) .sheet(isPresented: .constant(true), content: { NavigationStack { NavigationSplitView { List { Text("Item") } .navigationTitle("Title") } detail: { Text("Detail") } } .frame(width:600, height:400) // 可添加自定义工具栏按钮 .toolbar { Button("完成") { // 此处添加关闭Sheet的逻辑 } } }) } }
方案2:显式启用导航栏工具栏
如果不需要额外的NavigationStack,直接给NavigationSplitView设置工具栏可见性,也能让导航标题显示:
struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() .frame(width:800, height:800) .sheet(isPresented: .constant(true), content: { NavigationSplitView { List { Text("Item") } .navigationTitle("Title") } detail: { Text("Detail") } .frame(width:600, height:400) .toolbar(.visible, for: .navigationBar) }) } }
原因说明
在macOS的Sheet容器中,NavigationSplitView默认不会自动激活导航栏渲染机制。通过嵌入NavigationStack或显式设置.toolbar(.visible, for: .navigationBar),可以强制触发导航栏的显示逻辑,让navigationTitle和自定义栏项正常展示。
内容的提问来源于stack exchange,提问作者Stefan
相关产品推荐
相关产品推荐

