我第一次創建了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