ios - UICollectionView : Unrecognized selector sent to instance

标签 ios objective-c xcode

我遇到了这个错误。 *** 由于未捕获的异常“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/

相关文章:

android - 图片不显示在网站上?但是在手持设备上做

ios - 使用 Layer 使用 Swift 构建聊天功能的教程?

ios - 即使允许访问文件,startAccessingSecurityScopedResource() 也会返回 false

ios - 如何从主程序中检索 iOS 框架包中的文件/资源​​?

xcode Organizer "Validate"失败并显示 "No other information is available about the problem."消息

ios - 在 SceneKit 中使一个对象绕另一个对象运行

ios - 使用 Braintree 进行 iOS 订阅

ios - numberOfRowsInSection 方法调用了两次

ios - 在 Xcode 6/iOS 8 Interface Builder 启动屏幕中使用自定义字体

ios - 如何定义我的应用程序主屏幕组名称?