简体   繁体   English

如何为自定义UICollectionViewCell设置属性

[英]How do I set properties for my custom UICollectionViewCell

I am trying to set labels/buttons/images for a custom UICollectionViewCell that is being used as a sticky header. 我正在尝试为用作粘性标头的自定义UICollectionViewCell设置标签/按钮/图像。

These are my classes. 这些是我的课。

  1. ParlaxController ParlaxController
  2. CollectionViewCell CollectionViewCell
  3. AlwaysOnTop 总在最前面
  4. AlwaysOnTop.xib AlwaysOnTop.xib

-AlwaysOnTop inherits from CollectionViewCell. -AlwaysOnTop继承自CollectionViewCell。 In this class, I am setting properties and methods for the sticky header of my UICollectionView. 在此类中,我将为UICollectionView的粘性标头设置属性和方法。 -CollectionViewCell is for each individual collection cell. -CollectionViewCell适用于每个单独的收集单元。 -ParalaxController is where I set up my CollectionView delegate/datasource and manipulate my data. -ParalaxController是我设置CollectionView委托/数据源并处理数据的地方。

My question. 我的问题。 From my manipulated data in ParalaxController, how do I set this data to images and labels that I have connected to my AlwaysOnTop classes? 从ParalaxController中的操作数据中,如何将这些数据设置为已连接到AlwaysOnTop类的图像和标签? I also have buttons in my xib that need to manipulate data in my Paralax Controller. 我的xib中还有一些按钮需要在Paralax Controller中处理数据。

Thanks. 谢谢。

I needed to use viewForSupplmentryElementOfKind method like so. 我需要像这样使用viewForSupplmentryElementOfKind方法。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    if ([kind isEqualToString:CSStickyHeaderParallaxHeader]) {
        AlwaysOnTop *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
                                                                            withReuseIdentifier:@"header"
                                                                                   forIndexPath:indexPath];
        UIImage *albumArt = [UIImage imageNamed:@"noAlbumArt.png"];
        cell.albumArt.image = albumArt;

        return cell;
    }
    return nil;
}

Here I can update the header's view with data from my controller. 在这里,我可以使用控制器中的数据更新标题视图。

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

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