【发布时间】:2020-11-18 10:17:52
【问题描述】:
目前我有这个 loadCharacters 功能
var characterArray = [Character]()
func loadCharacters(with request: NSFetchRequest<Character> = Character.fetchRequest()) {
do {
characterArray = try context.fetch(request)
} catch {
print("error loading data")
}
collectionView.reloadData()
}
我的问题是:如何将获取的数据从那里传递给我的子类 CharacterCollectionViewCell,然后再将此单元格用于我的
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)
-> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "characterCell",
for: indexPath) as! CharacterCollectionViewCell {
...
}
非常感谢任何建议或任何更好的方法让它发挥作用!
【问题讨论】:
-
您想将 charachterArray 的一个索引传递给单元格子类?
标签: ios swift core-data uicollectionviewcell nsfetchrequest