0
Я создал UICollectionView в раскадровке и изменил его тип на пользовательский и выбрал подкласс UICollectionViewLayout в качестве своего класса.Подкласс 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;
}