菜鸟教程小白 发表于 2022-12-11 19:33:06

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


                                            <p><p>如何在我的 <code>UICollectionView</code> 中创建无限滚动?</p>

<p>附上截图:</p>

<p> <a href="/image/tdwSF.png" rel="noreferrer noopener nofollow"><img src="/image/tdwSF.png" alt="enter image description here"/></a> </p>

<p>现在我的 <code>NSArray</code> 是 </p>

<pre><code>NSArray* nameArr = ;
</code></pre>

<p><strong>我想在collectionView中创建一个Infinite Scrolling After Complete数组一次又一次地重复所有单元格。</strong></p>

<p><strong>无限滚动需要左右两边。</strong></p>

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

<p>谢谢!!!提前</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>首先将您当前的 NSArray 替换为 NSMutableArray 并在您的 cellForItemAtIndexPath 中进行上述更改</p>

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

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

   UICollectionViewCell *cell = ;

   UILabel *label = ;
   ];

   if(indexPath.row == nameArr.count-1) {
      ;
      ;
   }
   return cell;
}
</code></pre>

<p>在这里,我们一次又一次地添加相同的数组对象,因此它将无限滚动。
附截图:<a href="/image/Wn879.png" rel="noreferrer noopener nofollow">Refer This</a> </p>

<p>希望对你有帮助</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 iOS Objective-c 的 UICollectionView 中创建无限滚动,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/48076430/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/48076430/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 iOS Objective-c 的 UICollectionView 中创建无限滚动