我有一个选择器:
Section(header: Text("About you")) {
TextField("About you", text: $profileViewModel.bio)
Picker(selection: $profileViewModel.education,
label: Text("Education Level")) {
ForEach(Education.levels, id: \.self) { level in
Text(level).tag(level)
}
}
TextField("Occupation", text: $profileViewModel.occupation)
}
当我单击文本字段时,会出现键盘,这很好,但是当我单击选择器时,它会将我带到新屏幕以选择值并返回到表单。这在我的模拟器(iPhone 11 Pro Max)上运行良好:
Version 11.6 (921.9.1)
SimulatorKit 581.9.1
CoreSimulator 704.12.2
但是,当我在真实设备 iPhone X - v13.5.1 上测试此功能时,当我在文本字段(键盘可见)后单击选择器时,应用程序崩溃了。我不确定这是一个错误吗?
然后我将 ontapGesture 放入选择器以隐藏键盘:
Picker(selection: $profileViewModel.education,
label: Text("Education Level")) {
ForEach(Education.levels, id: \.self) { level in
Text(level).tag(level)
}
}.onTapGesture {
self.hideKeyboard()
}
这有时会起作用,但有时仍然会崩溃,即使当我将设备连接到 Xcode 并尝试获取日志时,我也没有收到任何错误,应用程序只是冻结了?