Answer the question
In order to leave comments, you need to log in
How to address 0 and 1 element, skipping the rest?
I want to figure out how it is possible to pass only the zero and first element, instead of all?
tried to make a loop
for IndexPath in 1 { ...}
got an error For-in loop requires 'Int' to conform to 'Sequence'
Any advice on what to do?
here is the function:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = mainView.collectionView.dequeueReusableCell(withReuseIdentifier: MainCollectionViewCell.cellId, for: indexPath) as! MainCollectionViewCell
cell.titlelabel.text = fetchedDataArray?[indexPath.row].title
cell.textLabel.text = fetchedDataArray?[indexPath.row].listDescription
cell.priceLabel.text = fetchedDataArray?[indexPath.row].price
cell.titleImageView.image = images?[indexPath.row]
switch indexPath {
case selectedIndexPath:
cell.checkMarkButton.isHidden = false
guard let cellTitleText = cell.titlelabel.text else {
return UICollectionViewCell()
}
selectedTitleString = cellTitleText
default:
cell.checkMarkButton.isHidden = true
}
return cell
}
Answer the question
In order to leave comments, you need to log in
"For-in loop" is for iterating over Sequences. You put instead of Sequence - number. Instead of a number, put a Sequence of the IndexPaths you need, and get what you need.
updated:
if you don't want only, always, and only the third element then :
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question