Я получаю сообщение об ошибке: Ошибка подтверждения в - [UICollectionView _dequeueReusableViewOfKind: withIdentifier: forIndexPath: viewCategory:] - PullRequest
0 голосов
/ 29 апреля 2019

У меня есть ViewController с несколькими UICollectionViews. Первоначально я начал с двух (myFavoritesCollectionView и allDealsCollectionView), и приложение работало достаточно. Однако, когда я добавил остальные, приложение начало падать.

Я установил точку останова исключения и получаю сообщение об ошибке:

2019-04-28 21: 00: 44.802033-0500 DiscountDays_ [67279: 13374922] *** Ошибка подтверждения в - [UICollectionView _dequeueReusableViewOfKind: withIdentifier: forIndexPath: viewCategory:], /BuildRoot/Library/Caches/com. .xbs / Источники / UIKitCore_Sim / UIKit-3698.103.12 / UICollectionView.m: 5417

И это выделяет строку:

let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "hello", for: indexPath) as? FastFoodCollectionViewCell

Ниже расширение на моем UIViewController:

 extension ViewController:UICollectionViewDelegate,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    if collectionView == self.myFavoritesCollectionView{
        print(myEmptyArray.count)
       return self.myEmptyArray.count
    }
    else if collectionView == self.fastFoodCollectionView{
        return self.fastFoodArray.count
    }
    else if collectionView == self.DessertsCollectionView{
        return self.dessertsArray.count
    }
    else if collectionView == self.sitDownRestrauntsCollectionView{
        return self.sitDownArray.count
    }
    else if collectionView == self.otherThanFoodCollectionView{
        return self.otherArray.count
    }
    else {
        print(allDiscounts.list.count)

        return allDiscounts.list.count
    }
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    if collectionView == myFavoritesCollectionView{
    let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "theLikes", for: indexPath) as? myLikesCollectionViewCell
    cell1?.companyLikedImage.image = UIImage(named: allDiscounts.list[myEmptyArray[indexPath.row]].imageName)
    cell1?.companyLikedName.text = allDiscounts.list[myEmptyArray[indexPath.row]].businessName
    cell1?.layer.cornerRadius = 11
        print("collectionviewlikes")
    return cell1!
    }
    else if collectionView == fastFoodCollectionView{
        let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "hello", for: indexPath) as? FastFoodCollectionViewCell
        cell2?.fastCompanyLikedImage.image = UIImage(named: allDiscounts.list[fastFoodArray[indexPath.row]].imageName)
        cell2?.fastCompanyLikedName.text = allDiscounts.list[fastFoodArray[indexPath.row]].businessName
        cell2?.layer.cornerRadius = 11
        print("collectionviewfast")
        return cell2!

    }
    else if collectionView.isEqual(DessertsCollectionView) {
        let cell3 = collectionView.dequeueReusableCell(withReuseIdentifier: "theDesserts", for: indexPath) as? DessertsCollectionViewCell
        cell3?.dessertsCompanyLikedImage.image = UIImage(named: allDiscounts.list[dessertsArray[indexPath.row]].imageName)
        cell3?.dessertsCompanyLikedName.text = allDiscounts.list[dessertsArray[indexPath.row]].businessName
        cell3?.layer.cornerRadius = 11
        print("collectionviewdesserts")
        return cell3!
    }
    else if collectionView == sitDownRestrauntsCollectionView {
        let cell4 = collectionView.dequeueReusableCell(withReuseIdentifier: "theSits", for: indexPath) as? sitDownCollectionViewCell
        cell4?.sitCompanyLikedImage.image = UIImage(named: allDiscounts.list[sitDownArray[indexPath.row]].imageName)
        cell4?.sitCompanyLikedName.text = allDiscounts.list[sitDownArray[indexPath.row]].businessName
        cell4?.layer.cornerRadius = 11
        print("collectionviewsit")
        return cell4!
    }
    else if collectionView == otherThanFoodCollectionView {
        let cell5 = collectionView.dequeueReusableCell(withReuseIdentifier: "theOthers", for: indexPath) as? OtherCollectionViewCell
        cell5?.otherCompanyLikedImage.image = UIImage(named: allDiscounts.list[otherArray[indexPath.row]].imageName)
        cell5?.otherCompanyLikedName.text = allDiscounts.list[otherArray[indexPath.row]].businessName
        cell5?.layer.cornerRadius = 11
        print("collectionviewother")
        return cell5!
    }
    else {
        let cell6 = collectionView.dequeueReusableCell(withReuseIdentifier: "allDeals", for: indexPath) as? allDealsCollectionViewCell
        cell6?.companyLikedImage1.image = UIImage(named: allDiscounts.list[indexPath.row].imageName)
        cell6?.companyLikedName1.text = allDiscounts.list[indexPath.row].businessName
        cell6?.layer.cornerRadius = 11
        print("collectionviewall")
        return cell6!
    }
}


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if collectionView == self.myFavoritesCollectionView {
    // handle tap events
    ViewController.searchStruct.buttonTag = myEmptyArray[indexPath.row]
    performSegue(withIdentifier: "gotocompany1", sender: self)
    }
    else if collectionView == self.fastFoodCollectionView {
        ViewController.searchStruct.buttonTag = fastFoodArray[indexPath.row]
        performSegue(withIdentifier: "gotocompany1", sender: self)
    }
    else if collectionView == self.DessertsCollectionView {
        ViewController.searchStruct.buttonTag = dessertsArray[indexPath.row]
        performSegue(withIdentifier: "gotocompany1", sender: self)
    }
    else if collectionView == self.sitDownRestrauntsCollectionView {
        ViewController.searchStruct.buttonTag = sitDownArray[indexPath.row]
        performSegue(withIdentifier: "gotocompany1", sender: self)
    }
    else if collectionView == self.otherThanFoodCollectionView {
        ViewController.searchStruct.buttonTag = otherArray[indexPath.row]
        performSegue(withIdentifier: "gotocompany1", sender: self)
    }
    else {
        ViewController.searchStruct.buttonTag = indexPath.row
        performSegue(withIdentifier: "gotocompany1", sender: self)
    }
}
}

В идеале, если код работает правильно, будет UIViewController с 6 UICollectionViews, который прокручивает по горизонтали каждый с отображением различных элементов.

...