在iOS7上的UIcollectionview中缺少项目

时间:2015-04-28 13:32:02

标签: ios uicollectionview

我创建了像Facebook Message这样的贴纸的集合视图,并在故事板中为它们添加了自动布局。它在iOS 8上没问题。但是当我在iOS 7上运行时,集合视图中的所有项目都消失了。有人能告诉我我的代码有什么问题以及如何解决这个问题? 这是我的代码:

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return stampCategorySelected.templetes.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    StampsCollectionViewCell *cell = (StampsCollectionViewCell*) [collectionView dequeueReusableCellWithReuseIdentifier:kStampCellIdentifier forIndexPath:indexPath];
    NSString *imgPath = [NSString stringWithFormat:@"%@/%@", STAMP_PATH, stampCategorySelected.templetes[indexPath.row]];
    cell.stamp.image = [UIImage imageNamed:imgPath];

    //Set page control count
    int pageCount = floor(collectionView.contentSize.width / collectionView.frame.size.width) + 1;
    _pagesControl.numberOfPages = pageCount;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(PC_Width/4, PC_Width/4);
}

#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    _clipart.kind = @"stamp";
    _clipart.clipartid = [stampCategorySelected.templetes[indexPath.row] stringByDeletingPathExtension];
    _clipart.clipartPath = stampCategorySelected.templetes[indexPath.row];
    _clipart.index = 0;
    _clipart.center = [Utilities arrayFromPoint:DEFAULT_CENTER];
    UIImage * clipartImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", STAMP_PATH, stampCategorySelected.templetes[indexPath.row]]];
    if (!clipartImage) {
        clipartImage = [UIImage imageNamed:[STAMP_PATH stringByAppendingPathComponent:stampCategorySelected.templetes[indexPath.row]]];
    }
    _clipart.size = @[@(_templateSize.width/5), @((clipartImage.size.height/clipartImage.size.width)*_templateSize.width/5)];
    _clipart.maxscale = 1;
    _clipart.scale = 1.0f;
    _clipart.angle = 0.0f;

    FSLog(@"Selected clipart: %@", _clipart);
    [_delegate stampViewController:self didSelectStamp:_clipart];
    [self dismiss:nil];
}

0 个答案:

没有答案