gpt4 book ai didi

ios - 设置 UICollectionViewController 时出错 - nib 但未获得 UICollectionView

转载 作者:可可西里 更新时间:2023-11-01 06:24:32 24 4
gpt4 key购买 nike

我在将自定义单元格设置到 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;
}

网格单元格

#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:

我什么都试过了,还是报错。

谢谢。

最佳答案

我在 Storyboard上添加 UICollectionViewController 作为嵌入式容器 View Controller 时遇到了这个问题。

我将容器 View Controller 的自定义类切换为 Collection View Controller 。但是 View Controller 中的 view 属性仍然是 Xcode 样板 UIView

删除 Storyboard上 Controller 中的默认 UIView 并将其替换为 UICollectionView。 socket 应自动重新连接。

关于ios - 设置 UICollectionViewController 时出错 - nib 但未获得 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24989741/

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