我在应用程序内部使用工作表,应用程序在所有工作表上都会显示导航标题.但出于某种原因,我没有在页面上看到导航标题,这是从应用程序的第一个视图出现的.我不知道为什么会发生这种事.
我有什么地方做错了吗?
我应用程序中的代码是这样的.内容视图包装在NavigationStack中.内容视图打开另一个视图(Firstview)作为导航目的地,此视图显示一个工作表,我希望在该工作表中显示导航标题和底部栏.我还没有开始在底部栏工作,但我不确定为什么导航标题没有显示.
100
import SwiftUI
import Foundation
struct ContentView: View {
@State private var showDetails = false
var body: some View {
NavigationStack {
VStack {
Button("First View") {
showDetails = true
}
}
.navigationDestination(isPresented: $showDetails) {
FirstView()
}
}
}
}
struct FirstView: View {
@State private var showDetails = false
var body: some View {
VStack {
Button("Show Sheet") {
showDetails = true
}
}
.sheet(isPresented: $showDetails) {
SheetView()
}
}
}
struct SheetView: View {
var body: some View {
VStack {
Text(getAttributedText()).font(.body)
Spacer()
}
// .navigationTitle("Settings") // This doesn't work nor does toolbaritem.
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("Settings").foregroundStyle(Color.black)
}
}
.interactiveDismissDisabled()
}
func getAttributedText() -> AttributedString {
var attributedString = AttributedString("")
var disclaimerText = AttributedString("This is an attributed text with links and underlined text. Some more text just for this sample app.")
disclaimerText.foregroundColor = .black
attributedString.append(disclaimerText)
return attributedString
}
}