我正在处理一个 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 使用了相同的方法并且图像显示正确。
感谢您的回复。
最佳答案
根据您发布的错误:
-[UICollectionViewCell img]: unrecognized selector sent to instance 0x7ff063f81170
原因很明显,从tableview中出队的cell实例没有方法“img”。
我想也许 reuseIdentifier 不正确,所以你得到了错误的类单元实例,它没有实现“img”方法。
关于ios - 在单元格的 ImageView 中设置图像时的 CollectionView NSInvalidArgument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51260327/