Контроллер представления коллекции не удалит ячейки из очереди - SWIFT - PullRequest
0 голосов
/ 09 января 2020

У меня есть 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 сумасшедшим, потому что я скопировал этот код с другого моего Контроллера, и этот Контроллер работает нормально.

Ответы [ 3 ]

2 голосов
/ 09 января 2020

Кажется, что setupCollectionView никогда не вызывается. Поместите это в viewDidLoad.

0 голосов
/ 09 января 2020

Функция, в которой вы регистрируете ячейку представления коллекции в представлении коллекции, никогда не вызывается. Мы не можем ожидать, что представление коллекции удалит из очереди ячейку, которая вообще не зарегистрирована в ней. Ваш код viewDidLoad должен выглядеть следующим образом:

override func viewDidLoad() {
    super.viewDidLoad()
    setupNavigation()
    setupCollectionView()
}
0 голосов
/ 09 января 2020

Из вашего кода, я думаю, вы не вызываете функцию setupCollectionView(). Просто попробуйте вызвать эту функцию в viewDidLoad() и проверьте результат.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...