Ios 如何设置图像和集合元素?

Ios 如何设置图像和集合元素?,ios,iphone,ios7,collections,uicollectionview,Ios,Iphone,Ios7,Collections,Uicollectionview,我喜欢克里特收藏,我想为它的元素设置图像。现在我可以只设置背景色了 我的代码: pragma标记-UICollectionViewDataSource方法 -(NSInteger)collectionView:(AFIndexedCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { NSArray *collectionViewArray = self.colorArray[collectionVi

我喜欢克里特收藏,我想为它的元素设置图像。现在我可以只设置背景色了

我的代码:

pragma标记-UICollectionViewDataSource方法

-(NSInteger)collectionView:(AFIndexedCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSArray *collectionViewArray = self.colorArray[collectionView.index];
return collectionViewArray.count;
}


-(UICollectionViewCell *)collectionView:(AFIndexedCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{    
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CollectionViewCellIdentifier forIndexPath:indexPath];

NSArray *collectionViewArray = self.colorArray[collectionView.index];
cell.backgroundColor = collectionViewArray[indexPath.item];

return cell;
}
AFTableViewCell

 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
 {
if (!(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) return nil;

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(10, 10, 9, 10);
layout.itemSize = CGSizeMake(44, 44);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView = [[AFIndexedCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CollectionViewCellIdentifier];
self.collectionView.backgroundColor = [UIColor whiteColor];
self.collectionView.showsHorizontalScrollIndicator = NO;
[self.contentView addSubview:self.collectionView];
回归自我; }

-(无效)布局子视图
{
[超级布局子视图];
self.collectionView.frame=self.contentView.bounds;
}
-(void)setCollectionViewDataSourceDelegate:(id)dataSourceDelegate索引:(NSInteger)索引
{
self.collectionView.dataSource=dataSourceDelegate;
self.collectionView.delegate=dataSourceDelegate;
self.collectionView.index=索引;
[self.collectionView-reloadData];
}

祝你好运:)事实上,你需要做的是在单元格的
contentView
中添加一个
UIImageView
@user3386109,是的,但是我有'-[AFTableViewCell setImageView:::]:未识别的选择器发送到实例0x8cd4c30'self.imageView=[[UIImageView alloc]init];self.imageView.frame=self.collectionView.frame;self.imageView.contentMode=UIViewContentModeScaleAspectFill;[self.contentView addSubview:self.imageView];
-(void)layoutSubviews
{
[super layoutSubviews];

self.collectionView.frame = self.contentView.bounds;
}

-(void)setCollectionViewDataSourceDelegate:(id<UICollectionViewDataSource, UICollectionViewDelegate>)dataSourceDelegate index:(NSInteger)index
{
self.collectionView.dataSource = dataSourceDelegate;
self.collectionView.delegate = dataSourceDelegate;
self.collectionView.index = index;

[self.collectionView reloadData];
}