【发布时间】:2014-10-17 14:25:17
【问题描述】:
我有一个UICollectionViewCell 子类,它现在只显示一个带有背景颜色的UIView 子视图,以表明它就在那里。
为了从 XIB 加载,我必须替换这个:
- (void)viewDidLoad {
[super viewDidLoad];
[self.localPlayerItemsView registerClass:[MBTradeCollectionViewCell class]
forCellWithReuseIdentifier:CellIdentifier];
}
用这个:
- (void)viewDidLoad {
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"MBTradeCollectionViewCell" bundle:nil];
[self.localPlayerItemsView registerNib:nib forCellWithReuseIdentifier:CellIdentifier];
}
这样做后,我会在collectionView:cellForItemAtIndexPath: 的第一行崩溃:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MBTradeCollectionViewCell *aCell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier
forIndexPath:indexPath];
return aCell;
}
这是崩溃:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7d461780> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key itemCountView.'
使用registerClass:forCellWithReuseIdentifier:时不会导致这个崩溃,但是它不会加载我的xib。
【问题讨论】:
-
检查 itemCountView 的自定义单元格插座连接。
-
听起来 IBOutlet 连接不正确。检查笔尖中的所有连接。
标签: ios objective-c xcode uicollectionview xib