【问题标题】:Create a gallery using UICollectionView iOS使用 UICollectionView iOS 创建图库
【发布时间】:2013-09-21 14:47:42
【问题描述】:

我想使用标签栏控制器上方的 uicollectionview 创建一个画廊。我遇到的问题是,当我连接 uicollectionview 数据源时,我遇到了 SIGABRT 崩溃。但是当我没有连接它时,控制器视图没有显示任何图像。有人知道该怎么做吗?

这是我制作的代码:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    NSLog(@"stiker : %d", stickers1.count);
    return stickers1.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";

    NSLog(@"indexpath row : %d", indexPath.row);

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
    recipeImageView.image = [UIImage imageNamed:[stickers1 objectAtIndex:indexPath.row]];
    //    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo-frame.png"]];

    return cell;
}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    NSLog(@"numberOfSectionsInCollectionView coll : %d, stic : %d", collectionView.numberOfSections, stickers1Collection.numberOfSections);

    return collectionView.numberOfSections;
}

我已经在xib中连接了uicollectionview数据源

【问题讨论】:

  • 显示数据源方法的代码。
  • @Amar 我已经更新了我的代码
  • 这个日志打印的是什么NSLog(@"stiker : %d", stickers1.count);
  • 我只是想查看图片数量,可以拒绝

标签: ios image uitabbarcontroller gallery uicollectionview


【解决方案1】:

设置项目数

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

设置内容 只需添加UIImageViewUIlabel 并在情节提要中设置标签并在cellForItemAtIndexPath 方法中分配数据

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

UIImageView *ImageView = (UIImageView *)[cell viewWithTag:100];
ImageView.image  = [UIImage imageNamed:[[arrCategoryValue objectAtIndex:indexPath.row] objectForKey:@"image"]];

UILabel *lbl = (UILabel *)[cell viewWithTag:200];
lbl.text = [[arrCategoryValue objectAtIndex:indexPath.row] objectForKey:@"name"];

cell.tag = indexPath.row;
return cell;
}

更多信息你可以去here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-14
    • 2013-03-28
    • 2020-08-16
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多