如何为自定义UICollectionViewCell设置属性

时间:2015-02-15 21:29:20

标签: ios objective-c xcode

我正在尝试为自定义UICollectionViewCell设置标签/按钮/图像,该自定义UICollectionViewCell用作粘性标头。

这些是我的课程。

  1. ParlaxController
  2. CollectionViewCell
  3. AlwaysOnTop
  4. AlwaysOnTop.xib
  5. -AlwaysOnTop继承自CollectionViewCell。在这个类中,我正在为我的UICollectionView的sticky标头设置属性和方法。 -CollectionViewCell用于每个单独的收集单元格。 -ParalaxController是我设置CollectionView委托/数据源并操纵我的数据的地方。

    我的问题。根据ParalaxController中的操作数据,如何将此数据设置为我连接到AlwaysOnTop类的图像和标签?我的xib中也有按钮需要操作我的Paralax Controller中的数据。

    感谢。

1 个答案:

答案 0 :(得分:1)

我需要像这样使用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;
}

在这里,我可以使用来自控制器的数据更新标题的视图。

相关问题