首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UICollectionView和UICollectionViewCell失效

UICollectionView和UICollectionViewCell失效
EN

Stack Overflow用户
提问于 2017-12-02 03:21:20
回答 1查看 148关注 0票数 1

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

紫色的原因是因为一开始我经验到我的主计根本没有露出来。因此,我将单元格变成灰色,并注意到在将集合视图变为紫色之后,它是不可见的。

我正在尝试用独特的图像和标签填充我的集合视图。这是我旅程的开始。

这是我的CollectionViewController

代码语言:javascript
运行
复制
#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个标签。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-02 04:22:37

尝试将委托添加到类接口中。

代码语言:javascript
运行
复制
@interface LoadZoneViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

将此添加到viewDidLoad

代码语言:javascript
运行
复制
[CollView registerNib:[UINib nibWithNibName:@"ZoneCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"YourCellIdentifier"];

这样做是在你的cellForItemAtIndexPath

代码语言:javascript
运行
复制
NSString *identifier = @"YourCellIdentifier";
ZoneCollectionViewCell *cell = (ZoneCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47604238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档