所以这是我的问题,我在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())
}
}
如果有人为此工作,或者知道发生了什么,我将不胜感激。
最佳答案
我可以找到的唯一解决此问题的方法是恢复使用UIKit。
关于ios - 在iOS 13.2中包装在普通UINavigationViewController中时,SwiftUI表单文本字段消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58773719/