繁体   English   中英

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

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

所以这是我的问题,我在 SwiftUI 中写了一个长表格。 在 iOS 13.1 中,表单工作正常。 现在使用 iOS 13.2,当我滚动时,表单中的 TextFields 会消失。 我需要表单在已经有很多 UIKit 视图的项目中工作,因此我将表单包装在 UIHostingController 中。 因此,UIHostingController 以编程方式从我的其他 ViewController 之一推送到 UINavigationViewController。

为了演示这个问题,我使用 XCode 11.2 (11B52) 创建了一个干净的项目,并在 iOS 13.2 模拟器中运行它。 字段消失。 在 iOS 13.1.2 上,这些字段按预期工作。

在新项目中使用下面的代码,并将 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())
    }
}

如果有人可以解决这个问题,或者知道发生了什么,我将不胜感激。

对于这个问题,我能找到的唯一解决方法是恢复使用 UIKit。

暂无
暂无

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

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