所以这是我的问题,我在SwiftUI中写了一个很长的表格。在iOS 13.1中,表单正常工作。现在使用iOS 13.2,当我滚动时,表单中的TextFields消失了。我需要表单在已经有很多UIKit视图的项目中工作,因此我将表单包装在UIHostingController中。因此,将UIHostingController从我的其他ViewController之一以编程方式推送到了UINavigationViewController。
为演示此问题,我使用XCode 11.2(11B52)创建了一个干净的项目,并在iOS 13.2模拟器中运行了该项目。字段消失。在iOS 13.1.2上,这些字段可以按预期工作。
在新项目中使用下面的代码,并将情节提要视图包装在UINavigationViewController中,然后将按钮连接到showForm(),将导致我遇到的问题。
import SwiftUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController {
@IBaction func showForm() {
navigationController?.pushViewController(FormViewController(),animated: true)
}
}
struct FormView: View {
@State private var text: String = ""
}
extension FormView {
var body: some View {
Form {
ForEach(0..<100) { index in
VStack {
Text("Question \(index)")
TextField("",text: self.$text)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
}
}
}
}
class FormViewController: UIHostingController<FormView> {
convenience init() {
self.init(rootView: FormView())
}
}
如果有人可以解决这个问题,或者知道发生了什么,我将不胜感激。