gpt4 book ai didi

swift - 为什么 SwiftUI 中的 Picker 只能工作一次

转载 作者:行者123 更新时间:2023-12-02 19:41:35 25 4
gpt4 key购买 nike

我从 SwiftUI 开始并创建了此代码

struct ContentView: View {

let countries = ["CZ","SK","DE"]
@State private var country = 0

var body: some View {
NavigationView {
VStack {
NavigationLink(destination: SettingsView()) {
Text("Settings")
}
Form {
Picker("Pick a country", selection: $country) {
ForEach(0..<countries.count) { index in
Text(self.countries[index])
}
}
Text(countries[country])
}
}
.navigationBarTitle("UNECE Data")
}
}
}

如果我从选择器中选择值,它会正确地将值返回到文本,但如果我再次执行相同的操作,则不会显示值列表,并且 XCode 会将其写入控制台窗口

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.

我将不胜感激任何建议。

最佳答案

是的,这是已知的错误,在真实设备上它可以工作。不光是你烦人……

根据您的情况(为了能够继续)您的开发,只需单击“设置”,然后返回,选择器将再次准备就绪。对了,尝试点击“设置”,返回再试一下。 “设置”链接也有同样的错误行为。

尝试苹果的主/详细模板,仅添加一个日期并检查它是否会以相同的方式工作。怎么可能呢? Swift 运行时不再是应用程序的一部分(由于 ABI)

它可以在 13.3 版本的真实设备上运行,当前 Xcode 上的最新 SDK 仍然是 13.2。 (检查您的项目设置)

使用不同的选择器样式可能会有所帮助。

关于swift - 为什么 SwiftUI 中的 Picker 只能工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60029218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com