使用UICollectionView iOS创建库
我想使用选项卡栏控制器上方的uicollectionview创建一个图库。我遇到的问题是,当我连接uicollectionview数据源时,会发生SIGABRT崩溃。但是当我没有连接它时,控制器视图没有显示任何图像。有人知道该怎么做吗 这是我编写的代码:使用UICollectionView iOS创建库,ios,image,uitabbarcontroller,gallery,uicollectionview,Ios,Image,Uitabbarcontroller,Gallery,Uicollectionview,我想使用选项卡栏控制器上方的uicollectionview创建一个图库。我遇到的问题是,当我连接uicollectionview数据源时,会发生SIGABRT崩溃。但是当我没有连接它时,控制器视图没有显示任何图像。有人知道该怎么做吗 这是我编写的代码: - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ NSLog(@"stik
- (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数据源设置项目数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
设置内容
只需添加UIImageView
和UIlabel
并在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;
}
有关详细信息,您可以转到显示数据源方法的代码。@Amar我已更新了我的代码打印的日志是什么
NSLog(@“stiker:%d”,stickers1.count)代码>?我只想检查图像计数,它可以被拒绝