Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when set UICollectionViewController - nib but didn't get a UICollectionView

I have a trouble when set custom cell into UICollectionViewController.

This is my code.

KidsDetailViewController.h

 #import <UIKit/UIKit.h>

 @interface KidsDetailViewController : UICollectionViewController <UICollectionViewDataSource>
 @property NSNumber *idCampana;

@property (weak, nonatomic) IBOutlet UICollectionView *grid;

@end

KidsDetailViewController.m

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

  return [grid_kid count];
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

GridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:self.truckImages[0]];

cell.prd_img.image = [UIImage imageNamed:@"ic_launcher_58x58"];

return cell;
}

GridCell.h

#import <UIKit/UIKit.h>

 @interface GridCell : UICollectionViewCell
 @property (weak, nonatomic) IBOutlet UIImageView *prd_img;

@end

GridCel.m

 #import "GridCell.h"

 @implementation GridCell

 - (instancetype)initWithFrame:(CGRect)frameRect {
      self = [super initWithFrame:frameRect];
      if (self) {
          // Initialization code
      }
   return self;
 }

 @end

This is the Error.

   *** Assertion failure in -[KidsDetailViewController loadView], /SourceCache/UIKit_Sim/UIKit-3283.1/UICollectionViewController.m:166
   2014-07-28 02:25:18.874 Geelbe[7673:231598] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] loaded the "jXd-Ir-mr4-view-0IK-5Q-NzC" nib but didn't get a UICollectionView.'
  *** First throw call stack:

I've tried everything and still gives error.

Thanks.

like image 424
Josué H. Avatar asked Dec 25 '22 06:12

Josué H.


2 Answers

I had this issue when adding a UICollectionViewController as an embedded container view controller on a storyboard.

I switched the container view controller's custom class to be a Collection View Controller. But the view property inside that view controller was still the Xcode boilerplate UIView.

Delete the default UIView within your controller on the storyboard and replace it with a UICollectionView. The outlets should be reconnected automatically.

like image 76
pkamb Avatar answered May 07 '23 17:05

pkamb


I think the problem may be because you inherit from UICollectionViewController, you do not have to specify anymore , because it already implements it. Try top delete it, see if it would fix your error.

Also in the Identity Inspector make sure you set the class KidsDetailViewController for the corresponding View Controller.

like image 20
ppalancica Avatar answered May 07 '23 18:05

ppalancica