Ari*_*ora 7 toolbar ios swift swiftui ios17
下一个代码片段是问题的示例。
import SwiftUI
struct TestingView: View {
@State var myText = ""
@State var myText2 = ""
var body: some View {
NavigationStack {
Form {
Text("Row 1")
Text("Row 2")
TextField("Write here", text: $myText)
TextField("Write here too", text: $myText2)
}
.navigationTitle("Testing Toolbar") // delete if you want no title
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Button {
print("Button up pressed")
} label: {
Image(systemName: "chevron.up")
}
Button {
print("Button down pressed")
} label: {
Image(systemName: "chevron.down")
}
Spacer()
}
}
}
}
}
struct TestingView_Previews: PreviewProvider {
static var previews: some View {
TestingView()
}
}
Run Code Online (Sandbox Code Playgroud)
它在 iOS 16.4 或更低版本上工作正常,但在 iOS 17 上不行。iOS 17 有什么解决方案吗?
找到了一个解决方法:向 NavigationStack 添加一个空的导航路径为我解决了这个问题(到目前为止)。
@State var path = NavigationPath()
NavigationStack(path: $path) {
...
}
Run Code Online (Sandbox Code Playgroud)