如何限制UICollectionViewCell

时间:2015-08-27 15:18:23

标签: objective-c uicollectionview uicollectionviewcell

如何将UICollectionViewCell限制为10或20?如果UICollectionViewCell从API加载了这么多单元格。

-(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;
}

2 个答案:

答案 0 :(得分:0)

限制self.items中的元素。 UICollectionView显示的单元格数量取决于collectionView:numberOfItemsInSection:方法,该方法完全取决于self.items中元素的数量。

答案 1 :(得分:0)

如果您想显示最多20 async void mouseEnter(object sender, MouseEventArgs e) { mouseIn = true; await Task.Delay(1000); if (mouseIn) { exp.IsExpanded = true; } } void mouseLeave(object sender, MouseEventArgs e) { mouseIn = false; } 秒(取决于UICollectionViewCell中的项目数):

self.items