【发布时间】:2020-02-04 12:00:20
【问题描述】:
我使用了UICollectionViewController,我正在尝试将图像添加到我的收藏视图单元格,但UICollectionView 方法未被调用。
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! CircularCollectionViewCell
cell.imageName = images[indexPath.row]
return cell
}
【问题讨论】:
-
行数是多少?您何时填充了
images数组?如果需要,你yourCollectionView.reloadData()了吗?在主线程中?它真的是 UICollectionViewController 还是 UIViewController 添加了 UICollectionView?如果那是一个添加的 UICollectionView,它的框架是什么? -
@KishanBhatiya 我用过collectionVC。我需要遵守委托和数据源吗?
-
您使用 Assets (xcassets) 还是手动文件夹:您是如何将图像添加到项目中的?
-
@Larme 我的
images数组正在填充,但cellForItemAt方法仍未被调用。我使用了一个手动文件夹,并将其作为带有蓝色图标的参考文件夹。 -
如果你使用 UICollectionViewController,数据源已经设置好了。我以为
images是空的,不是这样吗?完成后致电reloadData()?
标签: ios swift xcode uicollectionview