简体   繁体   English

子类化UICollectionViewCell,愚蠢的问题

[英]Subclassing UICollectionViewCell, silly issue

I'm trying to use a subclassed UICollectionViewCell I created. 我正在尝试使用我创建的子类UICollectionViewCell。

The only difference in my subclass is that the cell has an imageView property. 我的子类中的唯一区别是该单元格具有imageView属性。 I'm doing everything programatically - no storyboards or NIBs 我正在以编程方式进行所有操作-没有情节提要或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;

    }

}

However when I try to check if the cells imageView property is instantiated, I get, 但是,当我尝试检查是否已实例化单元格的imageView属性时,我得到了,

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UICollectionViewCell imageView]:无法识别的选择器已发送到实例

It's nearly like the cell doesn't know it's a PFUICollectionViewCell and still thinks it's a UICollectionViewCell. 几乎就像该单元格不知道它是PFUICollectionViewCell一样,仍然认为它是UICollectionViewCell。

I know this is a simple thing but I don't know what i'm doing wrong, 我知道这很简单,但是我不知道自己在做什么错,

Thanks, John 谢谢,约翰

Add code below in your -viewDidLoad method (or just after you created UICollectionView instance): 在您的-viewDidLoad方法中(或在创建UICollectionView实例之后)在下面添加代码:

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

UPD: UPD:

Oups, haven't seen this answer in comments. 哎呀,还没有在评论中看到这个答案。

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

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