小编Lef*_*eff的帖子

异步加载的图像在同一视图内不可重用

我的异步图像有问题。

这是文件的链接 https://www.vadimbulavin.com/asynchronous-swiftui-image-loading-from-url-with-combine-and-swift/

底部栏的图像不会因按钮操作而改变。我该如何解决它,你能解释一下吗?

podcastIndex 是 PodcastParser 类中的 @Publisched

文字改变也没有问题,但图像始终是一样的。

这是我的内容视图:

struct ContentView: View {

@ObservedObject var podcastParser = PodcastParser()

init() {
    podcastParser.loadData()
}

var body: some View {
    NavigationView {
        List(podcastParser.podcasts.indices) { index in
            HStack {
                Button(action: {
                    podcastParser.podcastIndex = index
                    print(podcastParser.podcasts[podcastParser.podcastIndex].imageUrl)
                }) {
                    HStack {
                        AsyncImage(
                            url: podcastParser.podcasts[index].imageUrl,
                            placeholder: {
                                Text("Loading...")
                            },
                            image: { Image(uiImage: $0).resizable() }
                        )
                        .scaledToFit()
                        .frame(width: 50, height: 50)
                        Text(podcastParser.podcasts[index].name)
                    }
                }
            }
        }
    }
    VStack {
        HStack {
            AsyncImage(
                url: podcastParser.podcasts[podcastParser.podcastIndex].imageUrl,
                placeholder: { …
Run Code Online (Sandbox Code Playgroud)

asynchronous image xml-parsing swiftui

2
推荐指数
1
解决办法
913
查看次数

标签 统计

asynchronous ×1

image ×1

swiftui ×1

xml-parsing ×1