uitableview - 表单中的 SwiftUI Pickers 出错:UITableView 被告知在不位于视图层次结构中的情况下布局其可见单元格和其他内容
问题描述
在表单中使用 SwiftUI 选择器出现此错误。当用户在显示的选项表中选择一个选项时会发生错误。
该错误仅发生在我运行 iOS 13.1 的物理设备 (iPhone 8) 上:它不会在模拟器中的 iOS 13.1 上发生。
这里有一些显示问题的屏幕:
表单中的 SwiftUI 选择器 Bug Screenshots
import SwiftUI
struct ContentView: View {
@State private var selectedLanguage: Language = .en
var body: some View {
NavigationView{
Form {
List{
Picker("Choose language", selection: $selectedLanguage){
ForEach(Language.allCases, id: \.self) { lang in
HStack{
Text(lang.rawValue)
}.tag(lang)
}
}.pickerStyle(DefaultPickerStyle())
}
}
}
}
}
enum Language: String, CaseIterable {
case en = " English"
case ch = " Chinees"
case ru = " Russian"
case es = " Spain"
case se = " Sweden"
var toString: String {
return self.rawValue
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
我希望复选标记在 iPhone 设备上正常工作,但我在设备上看不到任何复选标记并收到此错误:
UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window.
解决方案
推荐阅读
- r - drive_auth() 函数未在密码提交时创建 gargle-oauth 令牌
- android - 从 Firebase 数据库中检索数据时应用程序崩溃
- scala - 在火花中将列转换为二进制数据类型
- excel - 由于 Excel 未释放内存而导致的“内存不足”错误
- pandas - 将函数应用于数据框中的列列表
- google-apps-script - Google 表格 ImportXML 定期刷新且不缓存
- azure - 如何使用 AzureCLI 按日期删除 Azure Blob 存储中的文件?
- c - libavcodec/libx264 不尊重 keyint_min
- octave - 在 linux 控制台中为 UTF-8 配置 Octave
- html - CSS 行距:未在元素中应用