简体   繁体   中英

Subclassing UICollectionViewCell, silly issue

I'm trying to use a subclassed UICollectionViewCell I created.

The only difference in my subclass is that the cell has an imageView property. I'm doing everything programatically - no storyboards or NIBs

- (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,

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance

It's nearly like the cell doesn't know it's a PFUICollectionViewCell and still thinks it's a 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):

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

UPD:

Oups, haven't seen this answer in comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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