Ios 带有Api数据的SwiftUi水平滚动视图

Ios 带有Api数据的SwiftUi水平滚动视图,ios,swift,swiftui,scrollview,swiftui-list,Ios,Swift,Swiftui,Scrollview,Swiftui List,我需要用从api加载的数据创建一个水平滚动视图。 我有这样的看法: ScrollView(.horizontal,showsIndicators:false) { HStack(spacing: 20) { ForEach(self.images, id: \.self) { item in URLImage(URL(string:item)!) { proxy in

我需要用从api加载的数据创建一个水平滚动视图。 我有这样的看法:

 ScrollView(.horizontal,showsIndicators:false) {

      HStack(spacing: 20) {
        ForEach(self.images, id: \.self) { item in

                URLImage(URL(string:item)!)
                               { proxy in
                                   proxy.image
                                       .resizable()
                               }.frame(width: UIScreen.main.bounds.width - 120, height: 200).aspectRatio(contentMode: .fit)
                               .cornerRadius(15)
                               .opacity(0.7)


    }

    }.onAppear(perform: loadData)

}.padding(.all,20)
当我删除scrollview时,数据正在完美加载。对此有什么建议吗?谢谢尝试以下方法:

这是一个又快又脏的例子……;)

var-imageLoader=imageLoader()
类图像加载器{
变量图像:[图像]=[]
init(){
loadData()
}
func loadData(){

对于u0..当你将.onAppear修饰符移到ScrollView而不是HStack时会发生什么?@unequalsine nothing,white screen和Apple bug…我可以复制你的error@Chris这个错误有什么解决方案吗?只是一个解决方法:在显示视图之前加载图像。。。。
var imageLoader = ImageLoader()

class ImageLoader {

    var images : [Image] = []

    init() {
        loadData()
    }

    func loadData() {

        for _ in 0..<10 {
            images.append( Image(systemName: "circle.fill"))
        }
    }
}

struct ContentView: View {

       var body: some View {

        ScrollView(.horizontal,showsIndicators:false) {

        HStack(spacing: 20) {

                ForEach(0..<imageLoader.images.count, id: \.self) { item in

                    imageLoader.images[item]
                        .resizable()
                        .frame(width: UIScreen.main.bounds.width - 120, height: 200).aspectRatio(contentMode: .fit)
                        .cornerRadius(15)
                        .opacity(0.7)
                }
            }.background(Color.yellow)
        }.background(Color.orange)
    }
}