2015-08-27 67 views
0

如何將UICollectionViewCell限制爲10或20?如果UICollectionViewCell從API加載太多的單元格。如何限制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

也許你可以返回'numberOfItemsInSection'較少的項目。 – rmaddy

回答

0

限制self.items中的元素。 UICollectionView顯示的單元格數量取決於collectionView:numberOfItemsInSection:方法,該方法完全取決於self.items中元素的數量。

0

如果你想(在self.items取決於項目的數量),以顯示最多20個UICollectionViewCell S:

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

    return self.items.count; 
}