图片未显示在我的UICollectionView中

德里克·休伊特(Derek Hewitt)

所以我一直在寻找解决这个问题的方法,但是似乎什么也找不到。我有一个数组,可以使用以下方法加载图像路径

- (IBAction)btnPictures:(id)sender {

// Create the next view controller.
ImageGalleryViewController *galleryViewController = [[ImageGalleryViewController alloc] initWithNibName:@"ImageGalleryViewController" bundle:nil];


// Search for paths and get users home directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
// get path at first index (in case multiple returned
NSString *documentsDirectory = [paths objectAtIndex:0];

NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSArray *files = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension IN %@", @"png"]];

// Pass the selected object to the new view controller.
[galleryViewController setImageArray:files];

// Push the view controller.
[self.navigationController pushViewController:galleryViewController animated:YES];

}

然后将该图像数组发送到我的UICollectionViewController中的以下方法

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView       cellForItemAtIndexPath:(NSIndexPath *)indexPath{

ImageGalleryViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageGalleryViewCell" forIndexPath:indexPath];

NSLog(@"Image at index %@", [imageArray objectAtIndex:indexPath.row]);

[cell.galleryImage setImage:[UIImage imageWithContentsOfFile:[imageArray objectAtIndex:indexPath.row]]];

[cell setBackgroundColor:[UIColor whiteColor]];
return cell;
}

我验证了objectAtIndex通过我的NSLog返回了有效的图像名称,但是由于某些原因该单元格未显示它。

非常感谢您的任何帮助,在此先感谢您。

高拉夫·辛格(Gaurav Singh)

-contentsOfDirectoryAtPath:NSFileManager返回的数组不提供完整的文件路径,而仅提供文件和目录的名称。您必须将数组中的每个值附加到文档目录的路径。

像这样的东西:

NSString *documentsDirectoryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *imagePath = [documentsDirectoryPath stringByAppendingPathComponent:[imageArray objectAtIndex:indexPath.row]];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

图片未显示,无法在Laravel中更新我的图片

来自分类Dev

图片未显示在表格中

来自分类Dev

图片未显示在我的网站上

来自分类Dev

CSS背景图片未显示我的图片

来自分类Dev

来自数组的图像未显示在UICollectionview中

来自分类Dev

图片未显示在Android的Gallery App中

来自分类Dev

图片未显示在新闻通讯中

来自分类Dev

图片未显示在Image和ImageButton中

来自分类Dev

图片未显示在img标签中

来自分类Dev

Codeigniter:图片未显示在页面中

来自分类Dev

网页中未显示Fontasic图片

来自分类Dev

图片未显示在“闪亮”应用R中

来自分类Dev

图片未显示在javascript画布中

来自分类Dev

图片未显示在推送通知中

来自分类Dev

图片未显示在工具栏中

来自分类Dev

图片未显示在Production中(DEBUG = False)

来自分类Dev

图片未显示在Image和ImageButton中

来自分类Dev

图片未显示在img标签中

来自分类Dev

图片未显示在网页中

来自分类Dev

图片未显示在“闪亮”应用R中

来自分类Dev

图片未正确显示在帧布局中

来自分类Dev

图片未显示在 wordpress 媒体中

来自分类Dev

html 图片未显示在 JSF 模板中

来自分类Dev

图片未显示在 django 管理页面中

来自分类Dev

图片未显示在应用履历表中,[解决-这是我的错误编码]

来自分类Dev

Unity中的2D子画面未显示我分配给它的图片

来自分类Dev

上载的图片未显示在asp.net的图片控件中

来自分类Dev

图片未显示在图片框C#中

来自分类Dev

我的div背景图片未显示