SwiftUI ProgressView 在列表内时不显示
在下面的简单示例中,您会发现第一次点击Toggle Loading
时,ProgressView
按其应有的方式显示,但第二次(第三次点击)则不然。 看来是周围的List造成的。
有什么想法以及如何使其发挥作用吗?
struct ContentView: View {
@State private var isLoading = false
var body: some View {
List {
if isLoading {
HStack(alignment: .center, spacing: 10) {
ProgressView()
Text("Loading")
}
} else {
Text("Not Loading")
}
Button("Toggle Loading") {
isLoading.toggle()
}
}
}
}
In the following simple example you will find that the first time you tap Toggle Loading
the ProgressView
is shown as it should, but the second time (3rd tap) it's not.
It seems to be caused by the surrounding List.
Any ideas what the issue is and how to make it work?
struct ContentView: View {
@State private var isLoading = false
var body: some View {
List {
if isLoading {
HStack(alignment: .center, spacing: 10) {
ProgressView()
Text("Loading")
}
} else {
Text("Not Loading")
}
Button("Toggle Loading") {
isLoading.toggle()
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)