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
*** 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With