gpt4 book ai didi

ios - 为什么 collectionView 单元格不显示在 iOS 中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:01:56 26 4
gpt4 key购买 nike

您好,我可以从画廊获取图像,但 collectionViewCells 未显示在 UI 上。我拖放 collectionView 提供了与委托(delegate)和数据源方法的连接。但为什么没有获取 CollectionViewCells。我编写了这样的代码

- (void)viewDidLoad  
{
imagesArray = [NSMutableArray array];
[self.collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"CELL"];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
inputImage= info[UIImagePickerControllerEditedImage]; [imagesArray addObject:inputImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView; {
return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [imagesArray count];
}

- (MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
if(!cell) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL"forIndexPath:indexPath];
}
recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image =[imagesArray objectAtIndex:indexPath.row];
[collectionView reloadData];
return cell;
}

请有人建议我怎么做。感谢帮助

最佳答案

问题是您在 cellForItemAtIndexPath 中调用 reloadData。这将导致无限循环。

关于ios - 为什么 collectionView 单元格不显示在 iOS 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29002302/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com