集合视图前 3 项应该是静态的
Collection view first 3 item should be static
我有一个集合视图,前 3 个项目应该是静态的,然后是动态添加的。
检查我的以下代码:-
func numberOfSections(in collectionView: UICollectionView) -> Int {
//
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//
return 20
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//
// Configure the cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! AddProductInGroupCell
//cell.backgroundColor = UIColor.white
cell.layer.borderWidth = 0.4
cell.layer.borderColor = UIColor.lightGray.cgColor
cell.layer.cornerRadius = 2
if(3 > indexPath.row)
{
cell.ProductImage.image = UIImage(named : "folder.png")
cell.lableProduct.text = arrCellsLabel[indexPath.row]
cell.imageDotted.isHidden = true
cell.imageLike.isHidden = true
}
cell.delegate = self
return cell
}
当 运行 应用程序时,第一次正常显示(3 个静态单元格),但是当我们向下滚动并再次向上滚动时,5 个单元格显示静态。
该怎么办 ?
谢谢
因为单元格重复使用,部分代码可能是这样的:
if(3 > indexPath.row)
{
cell.ProductImage.image = UIImage(named : "folder.png")
}
else
{
cell.ProductImage.image = UIImage(named : "application.png")
}
我有一个集合视图,前 3 个项目应该是静态的,然后是动态添加的。
检查我的以下代码:-
func numberOfSections(in collectionView: UICollectionView) -> Int {
//
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//
return 20
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//
// Configure the cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! AddProductInGroupCell
//cell.backgroundColor = UIColor.white
cell.layer.borderWidth = 0.4
cell.layer.borderColor = UIColor.lightGray.cgColor
cell.layer.cornerRadius = 2
if(3 > indexPath.row)
{
cell.ProductImage.image = UIImage(named : "folder.png")
cell.lableProduct.text = arrCellsLabel[indexPath.row]
cell.imageDotted.isHidden = true
cell.imageLike.isHidden = true
}
cell.delegate = self
return cell
}
当 运行 应用程序时,第一次正常显示(3 个静态单元格),但是当我们向下滚动并再次向上滚动时,5 个单元格显示静态。
该怎么办 ?
谢谢
因为单元格重复使用,部分代码可能是这样的:
if(3 > indexPath.row)
{
cell.ProductImage.image = UIImage(named : "folder.png")
}
else
{
cell.ProductImage.image = UIImage(named : "application.png")
}