问题
如下代码所示,当点击表单中的“显示表格”按钮时,会出现一个包含TextEditor的表格。 当文本编辑器的键盘被隐藏(按键盘右下角的按钮),键盘被隐藏,表格也被关闭。
我希望这个表格不会被关闭。可能是SwiftUI的一个bug...
请帮助我找出表格为什么会被关闭以及如何防止它关闭。
我正在使用iPad Pro iOS 15.4.1。 在模拟器上不会出现这个问题。
struct ContentView: View {
@State var showSheet = false
@State var input = ""
var body: some View {
Form {
// Section 1
Section {
Text("1")
Text("1")
Text("1")
Text("1")
Text("1")
}
// Section 2
Section {
Text("1")
Text("1")
Text("1")
Text("1")
Text("1")
}
// Section 3
Section {
Text("1")
Text("1")
Text("1")
Text("1")
Text("1")
}
// Section 4
Section {
Button {
showSheet = true
} label: {
Text("show sheet")
}
.sheet(isPresented: $showSheet, onDismiss: {
print("dismissed")
}) {
TextEditor(text: $input)
}
}
// Section 5
// Section {
// Text("1")
// Text("1")
// Text("1")
// Text("1")
// Text("1")
// }
}
}
}
图片
我的尝试
- 如果移除第1、2或3部分,则问题不会发生
- 如果取消注释第5部分,则问题不会发生
- fullScreenCover也有相同的问题
.sheet(...)
放在Form
之外,这对我同样有效。 - workingdog support Ukraine