ios - 如何在 iOS Objective-c 的 UICollectionView 中创建无限滚动

标签 ios objective-c uicollectionview uicollectionviewcell infinite-scroll

如何在我的 UICollectionView 中创建无限滚动?

附上截图:

enter image description here

现在我的 NSArray

NSArray* nameArr = [NSArray arrayWithObjects: @"0", @"1", @"2", @"3", @"4", nil];

我想在完成数组一次又一次地重复所有单元格后在 collectionView 中创建一个无限滚动。

左右两侧需要无限滚动。

如果是,那我该如何实现,请在objective-c中给出引用。

谢谢!!!提前

最佳答案

首先用 NSMutableArray 替换你当前的 NSArray 并在你的 cellForItemAtIndexPath 中进行上述更改

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

- (__kindof UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

     UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

     UILabel *label = [cell viewWithTag:25];
     [label setText:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];

     if(indexPath.row == nameArr.count-1) {
        [nameArr addObjectsFromArray:nameArr.mutableCopy];
        [collectionView reloadData];
     }
     return cell;
}

这里我们一次又一次地添加相同的数组对象,因此它将无限滚动。 附截图:Refer This

希望对你有帮助

关于ios - 如何在 iOS Objective-c 的 UICollectionView 中创建无限滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48076430/

相关文章:

ios - 如何调节 UIVisualEffectView 模糊的级别

iphone - 控制台错误 : UICollectionView must be initialized with a non-nil layout parameter

ios - 使用 Photo Kit 和 Swift 在 UICollectionViewCell 中模糊图像

ios - 设置特定的 UITableView 行以推送到特定的详细信息 View 中?

ios - 在存在另一个 UIViewController 时防止滑动手势

iphone - 在 objective-c 中测试

ios - 在 NSView 层上设置仿射变换不像在 iOS 上那样工作

ios - 找出 UICollectionView 单元格中的多个按钮中的哪个被点击

ios - 共享扩展

ios - MMDrawerController 使用 Swift 预建动画