【发布时间】:2014-07-28 06:43:46
【问题描述】:
将自定义单元格设置为 UICollectionViewController 时遇到问题。
这是我的代码。
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:
我什么都试过了,还是报错。
谢谢。
【问题讨论】:
-
按照这些步骤 1. 退出 Xcode 2. 转到派生数据的文件夹并删除所有内容 3. 打开 Xcode 并执行产品清理 4. 运行您的应用程序
-
你的笔尖是从那个类派生的吗?检查您的文件所有者。