【发布时间】:2020-09-23 18:14:59
【问题描述】:
我正在使用以下代码以UICollectionView 的样式布置一些单元格。 ImageUploadViewCell 包含一些逻辑,用于在其 selected 标志在真假之间切换时更新单元格。
我不知道如何访问“发件人”视图。我是 SwiftUI 的新手,但过去做过很多 iOS。我是否对设计模式有错误的思考?我的单元格的数据源是否应该是 ObservableObject 并携带所有数据来呈现单元格?
请注意,dataStore 是 @EnvironmentObject
LazyVGrid(columns: columns, alignment: .center, spacing: 7) {
ForEach(dataStore.images.data.indices, id: \.self) { index in
ImageUploadViewCell(url: dataStore.images.data[index].thumbnail)
.aspectRatio(1, contentMode:.fill)
.frame(width: cellSize, height: cellSize)
.border(Color(UIColor.systemGray), width: self.selectMode ? 5 : 0)
.clipped()
.gesture(
TapGesture()
.onEnded { _ in
sender.selected.toggle() <--------- how do I do this?
self.selectedItems.append(index)
print(dataStore.images.data[index])
print(self.selectedItems)
}
)
}
}
【问题讨论】: