为什么collectionViewCells无法在iOS中显示?

瓦尼幸运

嗨,我可以从图库中获取图像,但collectionViewCells不在UI上显示。我将collectionView拖放到委托和datasourse方法的连接上,但是为什么没有得到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;
}

请任何人建议我该怎么做。帮助表示赞赏

宾托姆

确保您拥有imageArray数据。并尝试重新加载collectionViewimagePickerController:didFinishPickingMediaWithInfo:方法

- (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];
[self.collectionView reloadData];
[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]; 
return cell;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么VirtualBox中的FuryBSD无法显示GUI屏幕?

为什么GKVoiceChat无法在iOS中传输任何音频?

为什么数据无法显示在视图页面中?

在不显示任何内容后,Firefox中无法正确显示内联SVG,为什么?

为什么React Native Picker无法在iOS上显示?

为什么我的通知图标在Oreo中无法正确显示?

为什么我无法在CSS中显示英雄图像?

为什么这种通用代码无法在iOS中显示PDF,而在Android中却无法显示PDF?

为什么matplotlib中的图例无法正确显示颜色?

为什么我的boxplot无法显示在python中?

为什么无法在Swift的Webview中显示指示器?

为什么愿望清单中的数据无法显示

为什么svg无法在Angular应用中显示?

为什么我在Android中的RecyclerView无法正确显示视图?

为什么使用Xamarin Forms的iOS应用程序无法显示“真棒字体”?

为什么我的游戏板元素无法显示在html文件中是什么原因?

为什么[[maybe_unused]]无法在捕获的列表中显示?

为什么无法在文本字段中显示数据?

Python Super无法在示例中显示为什么?

为什么GetUserMedia无法在Google Chrome中显示视频?

为什么我的图片无法在Safari中显示但可以在Chrome中显示?

为什么输入字段在Chrome中无法正确显示?

为什么函数无法在php中显示值

我的collectionviewcells中显示的图像。iOS(快速)

为什么在iOS中将tableview样式分组后,目标c中的标题部分的视图无法正确显示,目标c

为什么我的ios 10中的uilabel无法扩展?

为什么iOS上的three.js的glTFLoader无法显示Monster模型?

为什么我无法在 ListView 中显示 Firebase 数据

无法弄清楚为什么我无法显示不在数组中的值的错误消息