我有一个问题navigationBarBackButtonHidden
修饰符。它不会隐藏导航后退按钮...
这是列表的源代码:
import SwiftUI
struct ContentView: View {
@State var showSheet = false
var body: some View {
NavigationView {
List(chatsData, id: \.self.id) { chat in
NavigationLink(destination: ChatView(chat: chat)) {
ChatRow(chat: chat)
}
}
.navigationBarTitle("Chats")
}
}
}
Here's a preview:
这是我希望隐藏“默认”后退按钮的视图的代码:
import SwiftUI
struct ChatView: View {
var chat: Chat
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@State var name: String = "Some text"
fileprivate var backButton: some View {
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Image(systemName: "chevron.left")
})
}
var body: some View {
NavigationView {
VStack(alignment: .leading, spacing: 0) {
Spacer()
TextField("Name's placeholder", text: $name)
.clipShape(Rectangle())
.overlay(Rectangle().stroke(Color("lightgray"), lineWidth: 2))
.lineLimit(5)
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: backButton)
.navigationBarTitle("\(chat.id)", displayMode: .inline)
}
}
}
However, when clicking on a list item from the 1st screenshot, here's what I get:
“
我通过将列表的代码更新为:
NavigationLink(destination: ChatView(chat: chat).navigationBarBackButtonHidden(true)) {
ChatRow(chat: chat)
}
然而,顶部和下一个视图的标题之间仍然存在巨大差距: