UIcollectionView Problem

Discussion in 'iOS Programming' started by erdinc27, May 22, 2017.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    I have a weird problem with collectionView. I load collectionView in this way.
    Code:
    - (void)viewDidLoad { 
        [super viewDidLoad];
        self.achievements = [self createAchievementsObjects];
        [self.achievementsCollectionView reloadData];
    }
    
    and those are the delegate methods

    Code:
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        AchievementCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"achievementCell" forIndexPath:indexPath];
        [cell setUpTheCellWithAchievement:self.achievements[indexPath.row]];
        return cell;
    }
    
    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
        return self.achievements.count;
    }
    
    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
        return 10;
    }
    
    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        
        NSInteger width = (self.view.frame.size.width - 40 ) / 3;
        return CGSizeMake(width, width);
    }
    
    it displays only 15 cells and when i scroll down notihg is shown. What is wrong here ?
     
  2. MarkCollette macrumors 68000

    MarkCollette

    Joined:
    Mar 6, 2003
    Location:
    Toronto, Canada
    #2
    If you put breakpoints or NSLog statements in collectionView:layout:sizeForItemAtIndexPath and collectionView:cellForItemAtIndexPath where you inspect all of the values you're using, what do you see?
     

Share This Page