繁体   English   中英

当我在 SwiftUI 中单击 Picker 两次时应用程序崩溃?

[英]App crashes when I click Picker in SwiftUI twice?

尝试遵循一些教程并制作了我的第一个选择器

    struct ContentView: View {
    @State var unitEntry = ""
    @State var unitInput = ""
    @State var unitOutput = 0

    let units = ["Celsius", "Fahrenheit", "Kelvin"];

    var body: some View {
        NavigationView{
            Form{
                Text("Hello, World!")

                TextField("Test", text: $unitEntry)
                    .keyboardType(.decimalPad)

                Picker("Entry unit", selection: $unitInput) {
                    Text("Hello, World!")
                    Text("Hello, World2!")
                }
            }
        }
    }
}

选择器工作,它转到另一个视图以在两个文本选项之间进行选择。 但是当我回去再次点击选择器时它崩溃了。

2020-01-19 18:32:38.593660-0500 UnitConversion[46718:2939869] [TableView] Warning once only: 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. Table view: <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7fe0e2086600; baseClass = UITableView; frame = (0 0; 414 896); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600002677f60>; layer = <CALayer: 0x6000028af160>; contentOffset: {0, -140}; contentSize: {414, 161.00000000000003}; adjustedContentInset: {140, 0, 34, 0}; dataSource: <_TtGC7SwiftUIP13$7fff2c69da4419ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS_19SelectionManagerBoxS2___: 0x7fe0bdc3e7c0>>
2020-01-19 18:32:40.477829-0500 UnitConversion[46718:2939869] Can't find keyplane that supports type 8 for keyboard iPhone-PortraitTruffle-DecimalPad; using 25739_PortraitTruffle_iPhone-Simple-Pad_Default
2020-01-19 18:32:40.504773-0500 UnitConversion[46718:2939869] Can't find keyplane that supports type 8 for keyboard iPhone-PortraitTruffle-DecimalPad; using 25739_PortraitTruffle_iPhone-Simple-Pad_Default

实际上,我认为你的挑剔者应该如下所示,并且你提供的日志并不指崩溃,如果有的话,它只是一个警告(正如它所说)并且不是由你的代码而是由 SwiftUI 内部产生的,所以可以忽略暂时(或提交 Apple 反馈)

@State var unitInput = "Celsius"

Picker("Entry unit", selection: $unitInput) {
    ForEach(units, id: \.self) { unit in
        Text(unit)
    }
}

我相信如果你在物理设备上运行它应该没问题。 我相信这是模拟器中的一个错误。

暂无
暂无

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

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