Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom UICollectionViewCell #34

Closed
cylak opened this issue Sep 4, 2018 · 1 comment
Closed

Use custom UICollectionViewCell #34

cylak opened this issue Sep 4, 2018 · 1 comment

Comments

@cylak
Copy link

cylak commented Sep 4, 2018

I want to use more than one UICollectionViewCell in the table view

Description:

I want to use more than one UICollectionViewCell in the table view but get fatal error like the custom cell didn't registered!
It works just with one view cell (default cell or custom cell) but if i want to use mixed of these i got error.
Thanks for your help 👍

Expected Behavior:

Show default cell with custom new cell

Actual Behavior:

Fatal error

Steps to Reproduce:

Custom cell -> GameCell.swift

import UIKit

class GameCell: UICollectionViewCell {
    
    static let id: String = "collectionViewCellID"
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    let imageView: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFill
        iv.layer.cornerRadius = 16
        iv.layer.masksToBounds = true
        iv.image = UIImage(named: "someImage")
        return iv
    }()
    
    func setupViews() {
        addSubview(imageView)
        
        imageView.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.width)
    }
}

GLCollectionTableViewCell.swift -> line 147

collectionView.register(GameCell.self, forCellWithReuseIdentifier: GameCell.id)

GLTableCollectionViewController.swift -> line 117

        if indexPath.item % 2 == 0 {
            guard let cell: GLIndexedCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: GLIndexedCollectionViewCell.identifier, for: indexPath) as? GLIndexedCollectionViewCell else {
                fatalError("UICollectionViewCell must be of GLIndexedCollectionViewCell type")
            }
            cell.backgroundColor = UIColor(hue: CGFloat(indexPath.item) / 20.0, saturation: 0.8, brightness: 0.9, alpha: 1)
            return cell
        }
        else{
            guard let cell: GameCell = collectionView.dequeueReusableCell(withReuseIdentifier: GameCell.id, for: indexPath) as? GameCell else {
                fatalError("UICollectionViewCell must be of GLIndexedCollectionViewCell type")
            }
            return cell
        }

Your Environment:

  • xCode: 9.4.1
  • GLTableCollectionView version: Last Version
  • Device: iPhone 6s (Real Device)
  • iOS version: 11.4
@cylak
Copy link
Author

cylak commented Sep 4, 2018

Sorry my bad, I found it!

GLTableCollectionViewController.swift -> line 117

        guard let indexedCollectionView: GLIndexedCollectionView = collectionView as? GLIndexedCollectionView else {
            fatalError("UICollectionView must be of GLIndexedCollectionView type")
        }
        if indexedCollectionView.indexPath.section % 2 == 0 {
            guard let cell: GLIndexedCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: GLIndexedCollectionViewCell.identifier, for: indexPath) as? GLIndexedCollectionViewCell else {
                fatalError("UICollectionViewCell must be of GLIndexedCollectionViewCell type")
            }
            cell.backgroundColor = UIColor(hue: CGFloat(indexPath.item) / 20.0, saturation: 0.8, brightness: 0.9, alpha: 1)
            return cell
        }
        else{
            guard let cell: GameCell = collectionView.dequeueReusableCell(withReuseIdentifier: GameCell.id, for: indexPath) as? GameCell else {
                fatalError("UICollectionViewCell must be of GLIndexedCollectionViewCell type")
            }
            return cell
        }

@cylak cylak closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant