I am creating a movie ticket app using collection view. I'm stuck arranging the seats in a collectionView. How to customise the custom flow layout? I want a particular amount of seats in specific rows of the collection view cells
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == leftCollectionView {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "leftcellid", for: indexPath) as! LeftSideMovieCollectionViewCell
let selectedseat = leftsideArray[indexPath.row]
if selectedSeatArray.contains(selectedseat) {
cell.leftMovieSeatImageView.image = UIImage.init(named: "seatfulled")
} else {
cell.leftMovieSeatImageView.image = UIImage.init(named: "seatblank")
}
if indexPath.row == 16 || indexPath.row == 17 || indexPath.row == 12 || indexPath.row == 13 {
cell.leftMovieSeatImageView.isHidden = true
} else {
cell.leftMovieSeatImageView.isHidden = false
}
return cell
} else if collectionView == RightCollectionview {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "rightcellid", for: indexPath) as! RightSideMovieCollectionViewCell
let selectedseat = rightsideArray[indexPath.row]
if selectedSeatArray.contains(selectedseat) {
cell.RightMovieseatImageView.image = UIImage.init(named: "seatfulled")
} else {
cell.RightMovieseatImageView.image = UIImage.init(named: "seatblank")
}
if indexPath.row == 18 || indexPath.row == 19 || indexPath.row == 14 || indexPath.row == 15 {
cell.RightMovieseatImageView.isHidden = true
} else {
cell.RightMovieseatImageView.isHidden = false
}
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "maincellid", for: indexPath) as! MainCollectionViewCell
let selectedseat = vipSeatArray[indexPath.row]
if selectedSeatArray.contains(selectedseat) {
cell.mainSeatImageView.image = UIImage.init(named: "seatfulled")
} else {
cell.mainSeatImageView.image = UIImage.init(named: "seatblank")
}
if indexPath.row == 43 || indexPath.row == 42 || indexPath.row == 34 || indexPath.row == 33 {
cell.mainSeatImageView.isHidden = true
} else {
cell.mainSeatImageView.isHidden = false
}
return cell
}
}
Here I have taken three collection views. I have hidden the particular cells. I don't know how to modify this. Can it be done with a single collection view? Any suggestions will be appreciated.