2015-08-27 2 views
0

Comment limiter UICollectionViewCell à 10 ou 20? Si UICollectionViewCell charger autant de cellules à partir de l'API.Comment limiter UICollectionViewCell

-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
    return 1; 
} 

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    return self.items.count; 
} 

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *identifier = @"Cell"; 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 
    eventisi* list = [_items objectAtIndex:indexPath.row]; 
    UIImageView *iconEvent = (UIImageView*)[cell viewWithTag:1]; 
    NSURL *url = [NSURL URLWithString:list.EVENT_IMAGE]; 
    [iconEvent setImageWithURL:url usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    iconEvent.clipsToBounds = YES; 
    // Configure the cell 
    UILabel *judul = (UILabel *)[cell viewWithTag:2]; 
    judul.text = list.EVENT_NAME; 
    judul.numberOfLines =2; 
    judul.lineBreakMode = NSLineBreakByWordWrapping; 
    judul.font = [UIFont systemFontOfSize:10]; 
    return cell; 
} 
+1

Peut-être que vous pouvez revenir dans moins d'éléments 'numberOfItemsInSection'. – rmaddy

Répondre

0

Limiter les éléments dans self.items. Le nombre de cellules affichées par UICollectionView dépend de la méthode collectionView:numberOfItemsInSection:, qui dépend entièrement du nombre d'éléments dans self.items.

0

Si vous souhaitez afficher un maximum de 20 UICollectionViewCell s (en fonction du nombre d'éléments self.items):

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    if(self.items.count >= 20) { 
     return 20; 
    } 

    return self.items.count; 
}