我试图将ProgressView
放在Picker
标签内。当我点击“隐藏微调器”按钮时,这会间歇性地崩溃,并显示EXC_BAD_ACCESS(code = EXC_I386_GPFLT)。
struct ContentView: View {
@State private var selectedCity = ""
@State private var showSpinner = true
let cities = [
"Calgary",
"Edmonton",
"Toronto"
]
var body: some View {
NavigationView {
VStack(spacing: 0) {
Form {
Picker(selection: $selectedCity, label:
HStack {
Text("Your City")
if showSpinner {
ProgressView()
.padding(.horizontal, 2)
}
}
) {
ForEach(cities, id: \.self) { city in
Text(city).tag(city)
}
}
Button("Hide Spinner", action: { showSpinner = false })
}
}
.navigationBarTitle("ProgressView Crash", displayMode: .inline)
}
}
}
我做错什么了吗?我猜这是一个SwiftUI错误。将UIActivityIndicatorView
包裹在UIViewRepresentable
中时,我得到相同的行为。
答案 0 :(得分:2)
是的,它看起来像带有自动生成的辅助功能标签的错误。安全的解决方法是使用显式提供的可访问性。
通过Xcode 12 / iOS 14测试
Picker(selection: $selectedCity, label:
HStack {
Text("Your City")
if showSpinner {
ProgressView()
.padding(.horizontal, 2)
}
}.accessibility(label: Text("Your City")) // << here !!
) {
ForEach(cities, id: \.self) { city in
Text(city).tag(city)
}
}