首页 > 解决方案 > 无法转换类型 '(Int) -> VStack 的值>' 到预期的参数类型 '(_) -> _'

问题描述

我的错误消息是:无法将“无法将类型“(Int)-> VStack>”的值转换为预期的参数类型“(_)-> _”类型的值

我知道代码的错误位是我在调用 getMedia 时使用 'array[index].documentID' 但我不知道为什么或如何解决。

请问你能帮忙吗?

这是我的视图代码:

struct weekDataList: View {
let weekDataF = weekDataFunc()
@ObservedObject var MainViews = MainView()
var body: some View {
    VStack {
        ForEach(array.count, id: \.self) { index in
            VStack{
                Button(action: {MainViews.getMedia(documentId: array[index].documentID)}) 
                               {Text(array[index].startDate + "-" + array[index].endDate)}
            }
        }.position(x:100,y:-100)
    }
}

标签: swiftui

解决方案


仅通过代码阅读,因为正如我评论的那样,快照不可编译

ForEach(0..<array.count) { index in
        ^^^^^^^^^^^^^^^ should be range and no id for indexes

推荐阅读