ios - 在单元格的 ImageView 中设置图像时的 CollectionView NSInvalidArgument

标签 ios objective-c uicollectionview uiimageview

我正在处理一个 Collection View 来提示图像,但我遇到了一个问题。当我尝试将图像设置到我的 UIImageView 时(在我的单元格中)它崩溃说 NSInvalidArgument 这里是日志:

-[UICollectionViewCell img]: unrecognized selector sent to instance 0x7ff063f81170
2018-07-10 10:10:50.645635+0200 App[41377:5706851]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UICollectionViewCell img]: 
unrecognized selector sent to instance 0x7ff063f81170'

这是错误的部分代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

   // Configure the cell
   cell.img.image = [UIImage imageNamed:@"test"];
   return cell;
}

我 100% 确定它应该工作,因为我对 UITableView 使用了相同的方法并且图像显示正确。

感谢您的回复。

更新: 这是我的 Storyboard的屏幕,如果它可以帮助的话: interface builder

最佳答案

根据您发布的错误:

-[UICollectionViewCell img]: unrecognized selector sent to instance 0x7ff063f81170

原因很明显,从tableview中出队的cell实例没有方法“img”。

我想也许 reuseIdentifier 不正确,所以你得到了错误的类单元实例,它没有实现“img”方法。

关于ios - 在单元格的 ImageView 中设置图像时的 CollectionView NSInvalidArgument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51260327/

相关文章:

ios - UITableView 的标签对于 UITableViewCell 来说太宽

ios - Swift UITableView 每 N 个单元格不同

ios - 无法保持选择表行

ios - UICollectionView,只是让单元格适合宽度?

ios - 居中的 UITextField 文本在编辑时意外移动

ios - UICollectionView 中来自 Realm 同步配置的种子数据

ios - 在 swift 中使用本地化字符串进行枚举

ios - 如何在 Swift 3/SpriteKit 中限制球的点击?

ios - NSDateComponent 给我一天递增 1

objective-c - 我应该使用 NSNumber 而不是基本的 C 数字类型吗?