admin管理员组文章数量:1293702
I am developing a SwiftUI app that displays a list of images using List and AsyncImage. However, I noticed that List keeps the cells in memory even when they scroll off-screen. I expected it to remove off-screen cells and reload them when they come back into view, but instead, it seems to cache them.
I did not set up URLCache, so the images should be loaded every time they appear on screen.
Here is my code:
NavigationStack {
List {
ForEach(viewModel.images) { image in
AsyncImage(url: URL(string: data.imageURL)) { phase in
let imageSize: CGFloat = 100
if let image = phase.image {
image.resizable()
.scaledToFill()
.frame(width: imageSize, height: imageSize)
.clipped()
} else if phase.error != nil {
Text(phase.error?.localizedDescription ?? "unexpected error")
.foregroundColor(Color.pink)
.frame(width: imageSize, height: imageSize)
} else {
ProgressView()
.frame(width: imageSize, height: imageSize)
}
}
}
}
本文标签: swiftSwiftUI List Doesn39t Remove OffScreen Cells When ScrollingStack Overflow
版权声明:本文标题:swift - SwiftUI List Doesn't Remove Off-Screen Cells When Scrolling - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741582391a2386645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论