Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何传递图像数据?_Ios_Objective C_Uiimageview - Fatal编程技术网

Ios 如何传递图像数据?

Ios 如何传递图像数据?,ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,我当前正在尝试将图像数据从一个导航控制器上的UIImageView传递到另一个导航控制器的UIImageView 基本上,我有一个collectionviewcontroller,当我按下图像时,它会将图像传递到我的navigationcontroller 1,在那里我有一个UIImageView。我一直做到这一步。但是,在我的navigationcontroller 1上,我有一个navigationbarbutton,它会将我带到navigationcontoller 2,它也有一个UIIm

我当前正在尝试将图像数据从一个导航控制器上的UIImageView传递到另一个导航控制器的UIImageView

基本上,我有一个collectionviewcontroller,当我按下图像时,它会将图像传递到我的navigationcontroller 1,在那里我有一个UIImageView。我一直做到这一步。但是,在我的navigationcontroller 1上,我有一个navigationbarbutton,它会将我带到navigationcontoller 2,它也有一个UIImageView,我想在这里将相同的图像从navigationcontoller 1传递到2,但选择将取决于我在集合视图中选择的图像

我需要如何编写此代码

抱歉有任何不准确之处,我刚刚开始学习如何编程,因此我的解释可能会含糊不清。所以如果你需要更多的信息,请告诉我

提前谢谢

**

编辑:

**

我的收藏视图控制器

@property (strong, nonatomic) NSArray *photoImages;
@property (strong, nonatomic) UIImage *photoImage;
@property (strong, nonatomic) NSArray *photoImages;
@property (strong, nonatomic) UIImage *detailPhotoImage;
CollectionViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

UICollectionViewCell *cell = (UICollectionViewCell *)sender;
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];

PictureViewViewController *pictureViewViewController = (PictureViewViewController *)segue.destinationViewController;
pictureViewViewController.photoImage = [UIImage imageNamed:[self.photoImages objectAtIndex:indexPath.row]];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DetailedPhotoViewViewController *detailedPhotoViewViewController = [segue destinationViewController];
detailedPhotoViewViewController.detailPhotoImage = photoImage;
}

PictureViewController.h

@property (strong, nonatomic) NSArray *photoImages;
@property (strong, nonatomic) UIImage *photoImage;
@property (strong, nonatomic) NSArray *photoImages;
@property (strong, nonatomic) UIImage *detailPhotoImage;
PictureViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

UICollectionViewCell *cell = (UICollectionViewCell *)sender;
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];

PictureViewViewController *pictureViewViewController = (PictureViewViewController *)segue.destinationViewController;
pictureViewViewController.photoImage = [UIImage imageNamed:[self.photoImages objectAtIndex:indexPath.row]];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DetailedPhotoViewViewController *detailedPhotoViewViewController = [segue destinationViewController];
detailedPhotoViewViewController.detailPhotoImage = photoImage;
}

DetailPhotoViewController.h

@property (strong, nonatomic) NSArray *photoImages;
@property (strong, nonatomic) UIImage *photoImage;
@property (strong, nonatomic) NSArray *photoImages;
@property (strong, nonatomic) UIImage *detailPhotoImage;
在PictureViewController中,我正在努力制定正确的prepareForSegue方法,以便在我的DetailPhotoViewController中显示相同的UIImage

我有一个带图片的收藏,我可以在点击图片时打开它。这将把图像传递到PictureView控制器,在那里它将全屏显示。在PictureView控制器上,我在导航栏中有一个按钮,该按钮显示注释,并应将其传递给DetailedPhotoViewController,在该控制器中,图片将显示在较小的视图中


希望这能澄清一点,谢谢你的耐心

如果我错了,请纠正我。。。我想您的意思是,您希望将UIImageView中显示的UIImage从一个UIViewController传递到另一个UIViewController,同时将新的UIImage推入UINavigationController堆栈

您所要做的就是为第二个ViewController设置UIImage属性,如

var myImage:UIImage?
之后,可以像这样将UIImage从旧控制器传递到第二个控制器,同时将第二个ViewController推入UINavigationController堆栈

if let theCont:SecondViewController = storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as? SecondViewController {
            theCont.myImage = UIImage(named: "imageFromOldController")
            self.navigationController?.pushViewController(theCont, animated: true)
        }

这只是一种方法。。。我认为这是最容易解释的

另一位发帖人的建议是合理的,但他用swift发布了自己的代码。从你问题中的标签判断,你在Objective-C中工作

在Objective-C中,等效于在目标视图控制器中设置并定义属性:

@property (nonatomic, strong) UIImage* myImage

…并在prepareForSegue方法中设置该属性(假设您使用的是故事板)

是的,他是对的,很抱歉,我没有看到目标C.:-)谢谢回复!你能解释一下我应该如何编写prepareForSegue方法吗?这正是我陷入困境的原因,因为在CollectionView中我定义了一个objectAtIndex:indexPath.row,但在NavgiationController 1中,我只有一个UIImage。因此,我对如何在这个NavigationController中编写prepareForSegue的实际代码感到困惑。如果不进一步了解应用程序的结构和功能,很难说。您的prepareForSegue可能会询问集合视图选择了哪些项,使用该信息获取所需的图像,从segue获取目标视图控制器,将其强制转换到自定义类,然后在目标中设置图像属性。我已经用代码编辑了我的问题。我不知道这是否会有所不同。