我第一次创建了UICollectionView。我错过了什么?我试过了所有的东西,图片肯定在应用程序中,正确命名并在数组中找到。然而他们没有得到显示:CollectionView不显示图标
我IconCell的标题:
#import <UIKit/UIKit.h>
@interface IconSelectionCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@end
实现我的IconCell:
#import "IconSelectionCell.h"
#import <QuartzCore/QuartzCore.h>
@implementation IconSelectionCell
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.restorationIdentifier = @"IconCell";
self.backgroundColor = [UIColor clearColor];
self.autoresizingMask = UIViewAutoresizingNone;
CGFloat borderWidth = 1.0f;
UIView *bgView = [[UIView alloc] initWithFrame:frame];
bgView.layer.borderColor = [UIColor blueColor].CGColor;
bgView.layer.borderWidth = borderWidth;
self.selectedBackgroundView = bgView;
CGRect myContentRect = CGRectInset(self.contentView.bounds, borderWidth, borderWidth);
UIView *myContentView = [[UIView alloc] initWithFrame:myContentRect];
myContentView.backgroundColor = [UIColor whiteColor];
myContentView.layer.borderColor = [UIColor colorWithWhite:0.5f alpha:1.0f].CGColor;
myContentView.layer.borderWidth = borderWidth;
[self.contentView addSubview:myContentView];
}
return self;
}
@end
而且我collectionViewController:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"IconCell";
IconSelectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.iconImageView.image = [UIImage imageNamed:[self.icons objectAtIndex:indexPath.row]];
return cell;
}
我需要通过代码添加imageview到单元格?我刚刚在界面生成器中创建了一个插座......或者我错过了什么?谢谢你的帮助!
您是否在控制器的.m文件中注册了您的单元类?你是否检查过单元的initWithFrame方法是否被调用? – rdelmar