Specify row and column number for UICollectionView

前端 未结 5 1805
失恋的感觉
失恋的感觉 2021-01-03 23:25

I want to show a UICollectionView which contains exactly 2 rows and 100 cells in each row.

// 1
- (NSInteger)collectionView:(UICollectionView *)view numberOf         


        
5条回答
  •  日久生厌
    2021-01-03 23:37

    Try this:

    // 1
    - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
    
        return 2;
    }
    // 2
    - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
        return 100;
    }
    // 3
    - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
            cell.lbl.text = @"Data";
    
        return cell;
    }
    

提交回复
热议问题