
var playResource: some View { LazyVStack(alignment: .leading) { ForEach(detailViewModel.videoDetail.ResourceModuleList, id: \.id) { item in LazyVStack { Text(item.title) ForEach(item.links, id:\.id) { a in LazyHStack { Button { } label: { Text(a.title) } } } } } } } 
报错文案: Cannot convert value of type '[ResourceLink]' to expected argument type 'Binding<C>'
请问这是什么原因呀?
谢谢各位大佬 我试了下,好像是Button的label中使用了Text的问题导致的,
Button { } label: { Text(a.title) } xcode的报错提醒的地方,往往不是出错的根本源头。。。这个很坑
1 lx01xsz 2024-04-10 18:47:29 +08:00 缺少上下文啊, 报错的源头貌似不是这 |
2 ma46 2024-04-11 09:15:31 +08:00 是要用 binding 类型吧, 就是那个美元符号的 |
3 Mephisto233 2024-04-11 10:29:53 +08:00 缺少上下文,看不出来,或者你把 detailViewModel.videoDetail.ResourceModuleList 和 item.links 里面的模型实现 Identifiable 协议 ,然后代码改成: ``` ForEach(detailViewModel.videoDetail.ResourceModuleList) { item in ... ForEach(item.links) { a in ..... } } ``` 再试试呢 |