我正在使用集合视图创建电影票应用程序。我被困在collectionView 中安排座位。如何自定义自定义流布局?我想要集合视图单元格的特定行中的特定数量的座位
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
}
}
在这里,我采取了三个集合视图。我已经隐藏了特定的单元格。我不知道如何修改这个。可以用一个集合视图来完成吗?任何建议将不胜感激。