swiftui - 无法转换类型 '(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)
}
}
解决方案
仅通过代码阅读,因为正如我评论的那样,快照不可编译
ForEach(0..<array.count) { index in
^^^^^^^^^^^^^^^ should be range and no id for indexes
推荐阅读
- powershell - 某些结果的输出格式表行颜色
- scala - 如何在scala中同时完成
- javascript - 如何返回此对象数组的总数?
- python - 使用多个条件查找最大值
- sql-server - 如何将多行中的一列连接起来,然后将该值插入另一行的单列中?
- android - 使用 Uri 加载从内部存储中选择的图像不起作用
- php - 如何使用可变变量 PHP 在 for 循环中创建字符串
- xpages - 浏览器后退按钮 - 中断 onClick 事件
- javascript - 使用 jquery 如何获取父 LI,其中 LI 的文本与我的按钮文本匹配?
- java - Spring AOP 不在代理类的 @Transactional 方法中注入事务