首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionViewLayout子类

UICollectionViewLayout子类
EN

Stack Overflow用户
提问于 2015-04-28 05:45:18
回答 1查看 83关注 0票数 0

我已经在情节提要中创建了一个自定义,并将其类型更改为UICollectionView,并选择了我的UICollectionViewLayout子类作为它的类。

在UICollectionViewLayout子类中有以下代码。但当我运行应用程序时,我在集合视图中根本看不到任何东西。我错过了什么?

代码语言:javascript
复制
@implementation CollectionViewLayout

- (id)initWithCoder:(NSCoder*)aDecoder
{
    if(self = [super initWithCoder:aDecoder]) {
        // Do something
        NSLog(@"init with coder");

        self.collectionView.backgroundColor = [UIColor redColor];

        self = [super init];

        self.imageArray = [NSMutableArray array];
        for(int i = 0; i <32; i++)
        {
            NSString *imageToLoad = [NSString stringWithFormat:@"%d.JPG", i];
            UIImage *image = [UIImage imageNamed:imageToLoad];
            [self.imageArray addObject:image];
        }

        longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
        longPress.delegate = self;
        [self.collectionView addGestureRecognizer:longPress];

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
        tapGesture.numberOfTapsRequired = 2;
        [self.collectionView addGestureRecognizer:tapGesture];

        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
    return [self.imageArray count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{

    NSLog(@"cell for item");

    Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
    [[cell viewWithTag:999] removeFromSuperview];
    self.isDeleteActive = NO;
    cell.image.image = [self.imageArray objectAtIndex:indexPath.row];
    return cell;
}
EN

回答 1

Stack Overflow用户

发布于 2015-04-28 10:15:59

代码语言:javascript
复制
 - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
 - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath

这些方法来自不应在自定义布局类中实现的“UICollectionViewDataSource”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29906537

复制
相关文章

相似问题

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