![](/img/trans.png)
[英]SwiftUI List with TextField adjust when keyboard appears/disappears
[英]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.