繁体   English   中英

子类化UICollectionViewCell,愚蠢的问题

[英]Subclassing UICollectionViewCell, silly issue

我正在尝试使用我创建的子类UICollectionViewCell。

我的子类中的唯一区别是该单元格具有imageView属性。 我正在以编程方式进行所有操作-没有情节提要或NIB

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    PFUICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"FlickrCell" forIndexPath:indexPath];
    cell.backgroundColor = [self generateRandomUIColor];


    NSURL *staticPhotoURL = [self.context photoSourceURLFromDictionary:[self.photos objectAtIndex:indexPath.row] size:OFFlickrSmallSize];



    **if (cell.imageView) {**

        cell.imageView = [self.pfImageViewArray objectAtIndex:indexPath.row];
        return cell;

    }

}

但是,当我尝试检查是否已实例化单元格的imageView属性时,我得到了,

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UICollectionViewCell imageView]:无法识别的选择器已发送到实例

几乎就像该单元格不知道它是PFUICollectionViewCell一样,仍然认为它是UICollectionViewCell。

我知道这很简单,但是我不知道自己在做什么错,

谢谢,约翰

在您的-viewDidLoad方法中(或在创建UICollectionView实例之后)在下面添加代码:

[collectionView registerClass:[PFUICollectionViewCell class]
   forCellWithReuseIdentifier:@"FlickrCell"];

UPD:

哎呀,还没有在评论中看到这个答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM