0

我想使用标签栏控制器上方的 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 数据源

4

1 回答 1

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;
}

欲了解更多信息,你可以去这里

于 2013-09-17T08:46:22.557 回答