Is there a way to display two types of cells (A, B) in the collection view and display the array values only in the cells of A?

Asked 2 years ago, Updated 2 years ago, 91 views

As shown in the picture, there are cells with values on the label and cells without displaying anything, but in this state, 3 seems to be in the cell where nothing is displayed (indexpath.row==2).
I'd like to shift the display of 3 by one to make it look like 1, 2, empty cells, 3, 4, is there any way? Enter a description of the image here

swift3 uicollectionview uicollectionviewcell

2022-09-30 21:28

1 Answers

The information displayed in the cell should be set in func collectionView(_collectionView:UICollectionView, cellForItemAtindexPath:IndexPath)->UICollectionViewCell.
All you have to do is write a program that sets what you want to see for the indexPath given there.
In this case, if you only want the third cell, or indexPath.item==2, to be a blank cell,

if indexPath.item<2{
    cell.label.text="\"(indexPath.item+1)"
} else if indexPath.item==2{
    cell.label.text="
} else{
    cell.label.text="\"(indexPath.item)"
}

All you have to do is write a branching process as shown in .
(Assume that the cell has a UILabel type property called label.Please adjust to your program.)


2022-09-30 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.