我已经在情节提要中创建了一个自定义,并将其类型更改为UICollectionView,并选择了我的UICollectionViewLayout子类作为它的类。
在UICollectionViewLayout子类中有以下代码。但当我运行应用程序时,我在集合视图中根本看不到任何东西。我错过了什么?
@implementation CollectionViewLayout
- (id)initWithCoder:(NSCoder*)aDecoder
{
if(self = [super initWithCoder:aDecoder]) {
// Do something
NSLog(@"init with coder");
self.collectionView.backgroundColor = [UIColor redColor];
self = [super init];
self.imageArray = [NSMutableArray array];
for(int i = 0; i <32; i++)
{
NSString *imageToLoad = [NSString stringWithFormat:@"%d.JPG", i];
UIImage *image = [UIImage imageNamed:imageToLoad];
[self.imageArray addObject:image];
}
longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
longPress.delegate = self;
[self.collectionView addGestureRecognizer:longPress];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[self.collectionView addGestureRecognizer:tapGesture];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
}
return self;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
return [self.imageArray count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
NSLog(@"cell for item");
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[[cell viewWithTag:999] removeFromSuperview];
self.isDeleteActive = NO;
cell.image.image = [self.imageArray objectAtIndex:indexPath.row];
return cell;
}发布于 2015-04-28 10:15:59
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath这些方法来自不应在自定义布局类中实现的“UICollectionViewDataSource”。
https://stackoverflow.com/questions/29906537
复制相似问题