ios - 在 UICollectionView 中每个部分显示两个单元格
<p><p>我正在使用 UICollectionView 显示图像,我已经存储在这样的数组中。</p>
<pre><code>newsPhotos = ;
</code></pre>
<p>我的想法是在这个订单上显示网格</p>
<pre><code>1 | 2
3 | 4
5 | 6
7 | 8
9 | 10
</code></pre>
<p>所以两张照片,我的 UICollectionView 方法如下所示:</p>
<pre><code>- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 2;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return newsPhotos.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Cell *cell = ;
UIImageView *recipeImageView = (UIImageView *);
recipeImageView.image = ];
cell.textLabel.text = @"Data";
return cell;
}
</code></pre>
<p>但它的打印是这样的</p>
<pre><code>1 | 1
2 | 2
3 | 3
etc..
</code></pre>
<p>我明白它为什么会发生,只是不知道如何解决它。有什么帮助吗?</p>
<p>谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个。 </p>
<pre><code>-(NSInteger)numberOfSectionsInCollectionView:
(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return newsPhotos.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Try and use custom cell by placing a custom cell on your collection view,assign a new class to that cell and then configure that cell as
customCellClass *myCell = ;
// also place an image view on your custom cell, make an outlet of that image view in your custom cell class and use:
myCell.imageview.image = ];
return myCell;
}
</code></pre>
<p>现在要每行显示两个图像,您可以相应地调整单元格和 ImageView 的大小,使其每行仅显示两个图像。
希望对你有帮助</p></p>
<p style="font-size: 20px;">关于ios - 在 UICollectionView 中每个部分显示两个单元格,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22651119/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22651119/
</a>
</p>
页:
[1]