当键盘被解散时,Swiftui表将自己关闭
问题
时,当代码显示↓时,当“显示表格”按钮被挖掘出来时会显示一张表。 该表仅包含一个文本编辑器。 当解散文本编辑器的键盘(按键盘中的右下按钮)时,键盘就会被取消,并且表也被删除。
我希望床单不会被解雇。也许这是Swiftui的一个错误...
请帮助我弄清楚为什么纸张被驳回以及如何预防。
我正在使用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节,问题不会发生
- ,则该问题不会出现
- 全屏幕中存在相同的问题
Problem
As the code shows↓, a sheet is presented when "show sheet" button in Form is tapped.
The sheet contains only a TextEditor.
When keyboard of the texteditor is dismissed (press the right bottom button in the keyboard), keyboard is dismissed, and the sheet is also dismissed.
I hope the sheet wouldn't be dismissed. Maybe it's a bug of SwiftUI...
Please help me figure out why the sheet is dismissed and how to prevent it.
I'm using iPad Pro iOS 15.4.1.
The problem doesn't occur on a simulator.
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")
// }
}
}
}
Picture
What I've tried
- if remove Section 1 or 2 or 3, the problem doesn't occur
- if uncomment Section 5, the problem doesn't occur
- fullScreenCover has the same problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将.sheet(...)放在表格外,对我有用。
try putting the .sheet(...) outside the Form, it works for me.