Post

Replies

Boosts

Views

Activity

App crashing while using collection view
I was trying to have a secondary collection view with circle images above (y axis) the functioning collection view but its crashing and throwing this error Error code: could not dequeue a view of kind: UICollectionElementKindCell with identifier CircleCollectionViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard ViewController code: // //  ViewController.swift //  Main_app // //  Created by Kushagr Agarwal on 23/08/21. // import UIKit class ViewController: UIViewController {     @IBOutlet var collectionView: UICollectionView!          @IBOutlet var topCollectionView: UICollectionView!          @IBOutlet weak var Leading: NSLayoutConstraint!          @IBOutlet weak var Trailing: NSLayoutConstraint!          @IBOutlet private weak var Menubutton: UIButton!     var menuOut = false               override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.         //self.navigationItem.titleView = UIImageView(image: UIImage(named: "Logo"))                  collectionView.register(MiddleCollectionViewCell.nib(), forCellWithReuseIdentifier: MiddleCollectionViewCell.identifier)                  collectionView.delegate=self         collectionView.dataSource=self                  topCollectionView.register(CircleCollectionViewCell.self, forCellWithReuseIdentifier: CircleCollectionViewCell.identifier)         topCollectionView.delegate=self         topCollectionView.dataSource=self //       Menu //       start                  let destructiveAction = UIAction(title: "Delete",image: UIImage(systemName: "nosign") , attributes: .destructive) { (_) in             print("Delete")         }                  let menu = UIMenu(title: "", children: [             UIAction (title: "Add New", image: UIImage(systemName: "plus.circle"), handler: { _ in  }),             UIAction (title: "Manage", image: UIImage(systemName: "hammer"), handler: { _ in  }),             destructiveAction         ])         self.Menubutton.menu = menu //    Menu end     } // Menu animation     @IBAction func MenuTap(_ sender: Any) {         if menuOut == false {             Leading.constant = -150             Trailing.constant = 150             menuOut = true         }         else{             Leading.constant = 0             Trailing.constant = 0             menuOut = false         }         UIView.animate(withDuration: 0.2, delay: 0.0 , options: .curveEaseIn,animations: {             self.view.layoutIfNeeded()         }){(animationComplete) in             print("Animation Completed")         }     } // Menu animation ends } // used for upper collection view extension ViewController: UICollectionViewDelegate {          func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {         collectionView.deselectItem(at: indexPath, animated: true )         print("btn tapped")              }           } extension ViewController: UICollectionViewDataSource {     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return 12     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MiddleCollectionViewCell.identifier, for: indexPath) as! MiddleCollectionViewCell         let topcell = collectionView.dequeueReusableCell(withReuseIdentifier: CircleCollectionViewCell.identifier, for: indexPath) as! CircleCollectionViewCell         topcell.configure(with: "")                  cell.configure(with: UIImage(named: "four")!)         return cell; topcell     } } //extension ViewController: UICollectionViewDelegateFlowLayout { // //}
1
0
2k
Sep ’21