简体   繁体   English

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

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

Trying to follow some tutorial and made my first picker尝试遵循一些教程并制作了我的第一个选择器

    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!")
                }
            }
        }
    }
}

The picker works, it goes to another view to pick between the two text options.选择器工作,它转到另一个视图以在两个文本选项之间进行选择。 But when I go back and tap the picker again it crashes.但是当我回去再次点击选择器时它崩溃了。

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

Actually the pickier in you case I assume should look like below and log which you provided does not refer to crash, if any, it is just a warning (as it stated) and originated not by your code but SwiftUI internals, so can be ignored for now (or submit Apple feedback)实际上,我认为你的挑剔者应该如下所示,并且你提供的日志并不指崩溃,如果有的话,它只是一个警告(正如它所说)并且不是由你的代码而是由 SwiftUI 内部产生的,所以可以忽略暂时(或提交 Apple 反馈)

@State var unitInput = "Celsius"

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

I believe it should be ok if you run it on a physical device.我相信如果你在物理设备上运行它应该没问题。 I believe it is a bug in the simulator.我相信这是模拟器中的一个错误。

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

相关问题 SwiftUI Picker 在通过 NavigationLink 显示时崩溃 - SwiftUI Picker crashes when displayed via NavigationLink SwiftUI Segmented Picker在点击时不切换 - SwiftUI Segmented Picker does not switch when click on it 当我通过鼠标单击更改 SwiftUI 列表的选择时,@Published 属性的 didSet 被调用了两次 - When I change selection of the SwiftUI List with mouse click didSet of the @Published property is called twice 当我单击 Google 登录按钮时,iOS 应用程序崩溃 - iOS app crashes when I click Google Sign-In button 单击侧栏菜单时应用程序崩溃 - App crashes when I click on side bar menu 从表单 (SwiftUI) 中的选择器上选择时扩展“其他”类别的应用程序 - App to expand 'Other' category when selected on picker from a form (SwiftUI)) SwiftUI 尝试展开/折叠工作表上的部分时应用程序崩溃 - SwiftUI app crashes when trying to expand/collapse sections on a sheet 使用 swiftUI 文本字段和 WKWebView 文本字段时应用程序崩溃 - App crashes when using a swiftUI textfield and a WKWebView textfield SwiftUI - 选择器更改时选择器绑定不更新 - SwiftUI - Picker binding not updating when picker changes Pickerview 在文本字段中第二次单击时显示为空,当我按下完成或取消应用程序崩溃时 - Pickerview is showing empty on second click in the textfield, adn when i press Done or Cancel the App crashes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM