我遇到了这个错误。 *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UICollectionViewCell 标签]:无法识别的选择器发送到实例 0x1eead660”
我正在使用 nib 文件作为我的单元格并尝试显示细胞正确。我猜我没有正确返回单元格,但我不太确定。任何帮助将不胜感激。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
NSMutableArray *data = [sections objectAtIndex:indexPath.section];
cell.label.text = [data objectAtIndex:indexPath.item];
return cell;
}
最佳答案
UICollectionViewCell 没有名为 label
的属性。
也许你的意思是:
[self.collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"Cell"];
假设您继承了 UICollectionViewCell
,添加了 label
,并调用了您的子类 Cell
。
关于ios - UICollectionView : Unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21993338/