我试图为初学者创建我自己的自定义UICollectionView,我在我的故事板中添加了一个CollectionView。

紫色的原因是因为一开始我经验到我的主计根本没有露出来。因此,我将单元格变成灰色,并注意到在将集合视图变为紫色之后,它是不可见的。
我正在尝试用独特的图像和标签填充我的集合视图。这是我旅程的开始。
这是我的CollectionViewController
#import "LoadZoneViewController.h"
#import "ZoneCollectionViewCell.h"
@interface LoadZoneViewController ()
@end
@implementation LoadZoneViewController
static NSString * const reuseIdentifier = @"Cell";
- (void)viewDidLoad {
[super viewDidLoad];
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
return 12;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
return 12;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
return cell;
}
#pragma mark <UICollectionViewDelegate>
@end我也定义了一个自定义UICollectionViewCell,但是我认为在修复这个问题之后,我应该担心这个问题。当前的问题只是标签没有出现,视图底部有一个滚动条,但我没有看到12个标签。
发布于 2017-12-02 04:22:37
尝试将委托添加到类接口中。
@interface LoadZoneViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>将此添加到viewDidLoad中
[CollView registerNib:[UINib nibWithNibName:@"ZoneCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"YourCellIdentifier"];这样做是在你的cellForItemAtIndexPath中
NSString *identifier = @"YourCellIdentifier";
ZoneCollectionViewCell *cell = (ZoneCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];https://stackoverflow.com/questions/47604238
复制相似问题