Ошибка со средствами выбора SwiftUI в форме: UITableView было приказано расположить видимые ячейки и другое содержимое, не находясь в иерархии представлений - PullRequest
0 голосов
/ 06 октября 2019

Получение этой ошибки с помощью средств выбора SwiftUI в форме. Ошибка возникает, когда пользователь выбирает выбор в представленной таблице вариантов.

Ошибка возникает только на моем физическом устройстве (iPhone 8) под управлением iOS 13.1: она не возникает с iOS 13.1 в симуляторах.

Вот некоторые экраны, демонстрирующие проблему:

Средства выбора SwiftUI в форме ошибки Снимки экрана

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.
...