gpt4 book ai didi

ios - 从 XIB 加载时 UICollectionViewCell 导致崩溃

转载 作者:行者123 更新时间:2023-12-01 17:22:35 24 4
gpt4 key购买 nike

我有一个 UICollectionViewCell子类,仅显示 UIView现在带有背景颜色的 subview ,以显示它在那里。

为了从 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。

最佳答案

在您的 MBTradeCollectionViewCell xib 文件,不要更改文件所有者的任何内容。更改top most view的类到 MBTradeCollectionViewCell,然后选择 itemCountView ,将其连接到您的top most view .希望这能解决问题。

关于ios - 从 XIB 加载时 UICollectionViewCell 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26427185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com