How to access TVPosterView inside UICollectionViewCell

317 Views Asked by At

As usual I encountered problem it is not well explained in internet and Apple documentation is limited.

I have UICollectionView with cells. I wanted to present movie poster inside each cell.I imported TVUIkit and addedd framework inside project settings.

My FilmCelkaCollectionViewCell.h contains

    API_AVAILABLE(tvos(12.0))
@interface FilmCelkaCollectionViewCell : UICollectionViewCell 
@property (strong, nonatomic) IBOutlet TVPosterView *widokPlakatu;

@end

FilmCelkaCollectionViewCell.m does not contain any methods.

And in my collectionviewcontroller cell definition is as follow:

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    UICollectionViewCell *celka = (FilmCelkaCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"filmCela" forIndexPath:indexPath];

    celka.backgroundColor =[UIColor greenColor];

    return celka;
}

I added green background to see better area in simulator. But problem is I don't know how to access property TVPosterView *widokPlakatu - the only thing I can access is celka.contentView. I watched WWDC2018 video about "What's new in tvos12" and still have questions:

  1. Does TVPosterView acts like CollectionViewCell and I can use it with UICollectionView without cells?
  2. Is TVPosterView some special @property that cannot be accessed and must be initialized somewhere,somehow? I defined property in storyboard.
  3. Is it forbidden to put views inside the CollectionViewCell?
1

There are 1 best solutions below

0
On

OK I found solution by accident.

This

FilmCelkaCollectionViewCell *celka = [collectionView dequeueReusableCellWithReuseIdentifier:@"filmCela" forIndexPath:indexPath];

will work while typecasting will not

UICollectionViewCell *celka = (FilmCelkaCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"filmCela" forIndexPath:indexPath];