Ios UICollectionView准备文件夹图像未传输

Ios UICollectionView准备文件夹图像未传输,ios,objective-c,json,storyboard,uicollectionview,Ios,Objective C,Json,Storyboard,Uicollectionview,我有一个UICollectionView,无法将图像传输到detailview。当我使用[pictures[row]]方法使用本地图像和图片数组时,detailview传输会起作用,但由于使用了SDWebImage框架,我无法做到这一点。一旦选定单元格,我就无法正确地将图像传输到详细视图。逻辑在第一个方法CellForItemAtIndexPath中解释。所选单元格和“准备分段”方法导致问题。如果你需要更多信息,请告诉我 -(UICollectionViewCell *)collectionVi

我有一个UICollectionView,无法将图像传输到detailview。当我使用[pictures[row]]方法使用本地图像和图片数组时,detailview传输会起作用,但由于使用了SDWebImage框架,我无法做到这一点。一旦选定单元格,我就无法正确地将图像传输到详细视图。逻辑在第一个方法CellForItemAtIndexPath中解释。所选单元格和“准备分段”方法导致问题。如果你需要更多信息,请告诉我

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

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

    NSString *pictures1 = [[pictures objectAtIndex:indexPath.row]objectForKey:@"filename"];
    comment = [[pictures objectAtIndex:indexPath.row] objectForKey:@"comment"];

    [cell.imageView setImageWithURL:[NSURL URLWithString:pictures1]
                    placeholderImage:[UIImage imageNamed:@"Earth.png"]
    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
     {
         NSLog(@"Error downloaidng images");
     }];


   // UIImage *image;

   // int row = [indexPath row];

    //image = [UIImage imageNamed:pictures[row]];

    //image = [UIImage imageWithData:imageUrl];

   // cell.imageView.image = image;

    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    UIImage *image;

    //int row = [indexPath row];

    NSString *pictures1 = [[pictures objectAtIndex:indexPath.row]objectForKey:@"filename"];
   // image = [UIImage imageNamed:pictures[row]];

    image = [UIImage imageNamed:pictures1];

    pictureDetailView *pictureDetail = [[pictureDetailView alloc]init];
    pictureDetail.image = image;

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UICollectionViewCell *)sender
{
    pictureDetailView *targetVC = (pictureDetailView *) [segue destinationViewController];
    NSIndexPath *indexPath = [self.collectionView indexPathForCell:sender];

    UIImage *image;

    //int row = [indexPath row];


    NSString *pictures1 = [[pictures objectAtIndex:indexPath.row]objectForKey:@"filename"];


   // image = [UIImage imageNamed:pictures[row]];

    image = [UIImage imageNamed:pictures1];

    //image = [UIImage imageWithData:imageUrl];

    targetVC.image=image;
}




@end

只需访问所选单元格的
imageView
,然后提取其图像。以下是如何做到这一点:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [self collectionView:collectionView cellForItemAtIndexPath:indexPath];
    UIImage *image = cell.imageView.image;

    // Pass the image to the next VC.
}

如果您需要更多帮助,请告诉我。

我正在开发的一个应用程序中遇到类似问题,无法找到有关收藏视图的任何帮助。下面是我使用的代码(更新以匹配您的方法)。我希望这能帮助你走上正轨。您还可以查看发布在上的演示项目。这帮助我解决了其中的一些问题

在CollectionViewController.h中: 在您的DetailViewController.h中
#导入
#导入“CollectionViewController.h”
@界面详细信息ViewController:UIViewController
@属性(强,非原子)IBUIImageView*imageView;
@属性(强,非原子)NSURL*imageURL;
@结束
在您的DetailViewController.m中
#导入“DetailViewController.h”
#进口
#导入“UIImageView+WebCache.h”
@接口详细信息ViewController()
@结束
@实现细节视图控制器
@合成imageURL=\u imageURL;
@综合imageView=\u imageView;
-(void)setImageURL:(NSURL*)imageURL
{
如果(_imageURL!=imageURL)
{
_imageURL=imageURL;
[自配置视图];
}
}
-(无效)配置视图
{
if(self.imageURL)
{
[self.imageView setImageWithURL:self.imageURL
占位符图像:无
选项:SDWebImageProgressiveDownload
已完成:^(UIImage*image,NSError*error,SDImageCacheType cacheType)
{
}];
}
}
-(无效)viewDidLoad
{
[超级视图下载];
[自配置视图];
}

此方法表示在对象类型UICollectionViewCell上找不到cell.imageView.image属性中的imageView。
#import <UIKit/UIKit.h>
#import "PictureDetailView.h"

@class PictureDetailView;

@interface CollectionViewController : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) PictureDetailView *detailViewController;

@end
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"yourSegueNameHere"]) {
        PictureDetailView *pictureDetail = segue.destinationViewController;
        NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] lastObject];
        NSString *largeImageURL = [pictures1 objectAtIndex:indexPath.row];
        pictureDetail.imageURL = [NSURL URLWithString:largeImageURL];
    }
}
#import <UIKit/UIKit.h>
#import "CollectionViewController.h"

@interface DetailViewController : UIViewController 

@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) NSURL *imageURL;

@end
#import "DetailViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"

@interface DetailViewController ()

@end

@implementation DetailViewController

@synthesize imageURL = _imageURL;
@synthesize imageView = _imageView;


- (void)setImageURL:(NSURL *)imageURL
{
    if (_imageURL != imageURL)
    {
        _imageURL = imageURL;
        [self configureView];
    }
}

- (void)configureView
{
    if (self.imageURL)
    {
        [self.imageView setImageWithURL:self.imageURL
                       placeholderImage:nil
                        options:SDWebImageProgressiveDownload
                        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
         {
         }];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configureView];
}