单ViewController中两个UICollectionView报错求助
Hey there, let's break down why you're hitting this error and how to fix it straight away. That error message is telling you your app can't locate a collection view cell with the identifier InProgressCVC — this almost always happens because you haven't properly registered the cell or linked it up in your storyboard.
Option 1: If you're using a prototype cell in Storyboard
If you built InProgressCVC as a prototype cell directly in your Storyboard, follow these steps to fix the issue:
- Open your Storyboard and navigate to the
FeedVCscene. - Locate the
collectionViewProgressUICollectionView. - Select its prototype cell, then open the Attributes Inspector:
- Make sure the Identifier field is exactly
InProgressCVC(capitalization and spelling matter!).
- Make sure the Identifier field is exactly
- Next, open the Identity Inspector for that prototype cell:
- Confirm the Class is set to
InProgressCVC(not the defaultUICollectionViewCell).
- Confirm the Class is set to
- Double-check that your
collectionViewProgressIBOutlet is correctly connected to the CollectionView in the Storyboard (no broken connection lines).
Option 2: If you're using a separate XIB or code-only cell
If your InProgressCVC lives in a separate XIB file or is written entirely in code, you need to register it explicitly in viewDidLoad:
For a XIB-based cell:
Add this line right after setting the delegate and dataSource for collectionViewProgress:
collectionViewProgress.register(UINib(nibName: "InProgressCVC", bundle: nil), forCellWithReuseIdentifier: "InProgressCVC")
For a code-only cell:
Use this line instead:
collectionViewProgress.register(InProgressCVC.self, forCellWithReuseIdentifier: "InProgressCVC")
Quick double-check
Since your first collection view (collectionView) is working, compare its setup to collectionViewProgress — you almost certainly missed the same registration/linking step for the second one. Also, make sure InProgressCVC properly subclasses UICollectionViewCell (no typos in the class definition!).
内容的提问来源于stack exchange,提问作者Robbie Wais

