如何在我的 UICollectionView
中创建无限滚动?
附上截图:
现在我的 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/