У меня есть CollectionViewController, в котором все настроено правильно, я знаю это, потому что у меня есть другие настройки CollectionViewController и он работает нормально. Однако, кажется, есть проблема с этим.
class AboutServiceController:UICollectionViewController{
var serviceID:String!
var serviceDescription:String = ""
override func viewDidLoad() {
super.viewDidLoad()
setupNavigation()
}
func setupNavigation(){
navigationController?.setNavigationBarHidden(false, animated: true)
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationBar.barTintColor = UIColor.white
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack")!.withRenderingMode(.alwaysOriginal),style: .plain, target: self, action: #selector(menuButtonTapped(sender:)))
self.title = "About this service"
}
func setupCollectionView(){
let inset = UIEdgeInsets(top: 0, left: 25, bottom: 80, right: 25)
collectionView.contentInset = inset
collectionView.backgroundColor = UIColor(red: 250/255, green: 250/255, blue: 250/255, alpha: 1)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(TitleHeaders.self, forSupplementaryViewOfKind:UICollectionView.elementKindSectionHeader, withReuseIdentifier: "Header")
collectionView.register(ImagesCell.self, forCellWithReuseIdentifier: "ImagesCell")
collectionView.register(AboutServiceCell.self, forCellWithReuseIdentifier: "AboutServiceCell")
collectionView.register(MapViewCell.self, forCellWithReuseIdentifier: "MapViewCell")
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
3
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
1
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.section {
case 1:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MapViewCell", for: indexPath) as! MapViewCell
return cell
case 2:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImagesCell", for: indexPath) as! ImagesCell
return cell
default:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AboutServiceCell", for: indexPath) as! AboutServiceCell
if(serviceDescription == ""){
cell.jobDesciption.text = "This user currently does not have any extra information about this service."
} else {
cell.jobDesciption.text = serviceDescription
}
return cell
}
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let reusableview = UICollectionReusableView()
switch kind {
case UICollectionView.elementKindSectionHeader:
//FOR HEADER VIEWS
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Header", for: indexPath) as! TitleHeaders
switch indexPath.section {
case 1:
headerView.messageBoardText.text = "Service Location"
case 2:
headerView.messageBoardText.text = "Photos"
default:
headerView.messageBoardText.text = ""
}
return headerView
default:
return reusableview
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
switch section {
case 0:
return CGSize(width: 0, height: 0)
default:
let indexPath = IndexPath(row: 0, section: section)
let headerView = self.collectionView(collectionView, viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: indexPath)
return headerView.systemLayoutSizeFitting(CGSize(width: collectionView.frame.width, height: UIView.layoutFittingExpandedSize.height),
withHorizontalFittingPriority: .required, // Width is fixed
verticalFittingPriority: .fittingSizeLevel)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
switch indexPath.section {
case 0:
return CGSize(width: view.frame.width, height: 150)
case 1:
return CGSize(width: view.frame.width, height: 350)
default:
return CGSize(width: collectionView.bounds.width/3.0 - 8, height: collectionView.bounds.width/3.0 - 8)
}
}
@objc func menuButtonTapped(sender: UIBarButtonItem) {
switch sender {
case self.navigationItem.leftBarButtonItem:
self.dismiss(animated: true, completion: nil)
default:
break
}
}
}
По какой-то странной причине он говорит мне, что говорит, что не может удалить из очереди ячейку AboutServiceCell, даже если я зарегистрировал ее в viewDidLoad, как вы можете видеть. Это делает меня go сумасшедшим, потому что я скопировал этот код с другого моего Контроллера, и этот Контроллер работает нормально.