简体   繁体   中英

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. In iOS 13.1, the form worked properly. Now with iOS 13.2, the TextFields I have in the form disappear when I scroll. 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. So the UIHostingController is pushed to the UINavigationViewController programmatically from one of my other ViewControllers.

To demonstrate the issue, I've created a clean project using XCode 11.2 (11B52) and ran it in the iOS 13.2 simulator. The fields disappear. On iOS 13.1.2 the fields work as expected.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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