简体   繁体   English

SwiftUI 表单文本字段在 iOS 13.2 中的普通 UINavigationViewController 中包装时消失

[英]SwiftUI Form TextField Disappears When Wrapped In A Normal UINavigationViewController In iOS 13.2

So here is my problem, I have a long form I wrote in SwiftUI.所以这是我的问题,我在 SwiftUI 中写了一个长表格。 In iOS 13.1, the form worked properly.在 iOS 13.1 中,表单工作正常。 Now with iOS 13.2, the TextFields I have in the form disappear when I scroll.现在使用 iOS 13.2,当我滚动时,表单中的 TextFields 会消失。 I need the form to work in a project that already has a lot of UIKit views, and so I've wrapped the form in a UIHostingController.我需要表单在已经有很多 UIKit 视图的项目中工作,因此我将表单包装在 UIHostingController 中。 So the UIHostingController is pushed to the UINavigationViewController programmatically from one of my other ViewControllers.因此,UIHostingController 以编程方式从我的其他 ViewController 之一推送到 UINavigationViewController。

To demonstrate the issue, I've created a clean project using XCode 11.2 (11B52) and ran it in the iOS 13.2 simulator.为了演示这个问题,我使用 XCode 11.2 (11B52) 创建了一个干净的项目,并在 iOS 13.2 模拟器中运行它。 The fields disappear.字段消失。 On iOS 13.1.2 the fields work as expected.在 iOS 13.1.2 上,这些字段按预期工作。

Using the code below in a new project, and wrapping the storyboard view in a UINavigationViewController and then wiring a button to showForm() will result in what I'm experiencing.在新项目中使用下面的代码,并将 storyboard 视图包装在 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())
    }
}

If anyone has a work around for this, or knows what's going on I'd appreciate it.如果有人可以解决这个问题,或者知道发生了什么,我将不胜感激。

The only fix I could find for this issue was to revert to using UIKit.对于这个问题,我能找到的唯一解决方法是恢复使用 UIKit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM