У меня есть UICollectionView
с UICollectionViewDataSource
, который в настоящее время предоставляет шесть предметов. Это меньше, чем необходимо для заполнения экрана. Проблема в том, что мой просмотр коллекции только прокручивается, когда для заполнения экрана достаточно элементов (проверено 10, 20). При отображении меньшего количества элементов он даже не сделает эту анимацию отказов, которую я пытаюсь получить, она просто исправлена.UICollectionView не прокручивает
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCollectionViewData) name:UIDocumentStateChangedNotification object:nil];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.itemSize = CGSizeMake(160, 100);
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 0;
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.bounces = YES;
[self.view addSubview:self.collectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.collectionViewData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Expense *expense = [self.collectionViewData objectAtIndex:indexPath.row];
UILabel *label = [[UILabel alloc]initWithFrame:cell.bounds];
label.text = expense.value;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"Miso-Bold" size:30];
label.textAlignment = NSTextAlignmentCenter;
[cell addSubview:label];
cell.backgroundColor = [UIColor colorWithRed:1 - (indexPath.row/30.0f) green:0 blue:1 alpha:1];
return cell;
}
Благодарим за помощь!
Это правильный ответ - OP должен принять это как ответ. –
отличная подсказка спасибо – Fattie
Спасибо, это работает как шарм :) – evya