Reputation: 21
I am currently trying to pass Image data from an UIImageView on one Navigation Controller to another Navigation Controller's UIImage View.
Basically, I've got a collectionviewcontroller where I have images when I press an image it will pass it to my navigationcontroller 1 where I have an UIImageView. I managed it up until this step. However, on my navigationcontroller 1 I've got a navigationbarbutton that will bring me to navigationcontoller 2 which also has an UIImageView and this is where I want to pass the same image from navigationcontoller 1 to 2 but the selection will depend on what image I have selected in the collection view.
How would I need to code this?
Apologies for any inaccuracies, I have just started to learn how to program thus my explanations could be vague. So if you need anymore information please let me know.
Thanks in advance!
**
Edit:
**
My CollectionViewController.h
@property (strong, nonatomic) NSArray *photoImages;
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]];
}
PictureViewController.h
@property (strong, nonatomic) UIImage *photoImage;
@property (strong, nonatomic) NSArray *photoImages;
PictureViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DetailedPhotoViewViewController *detailedPhotoViewViewController = [segue destinationViewController];
detailedPhotoViewViewController.detailPhotoImage = photoImage;
}
DetailPhotoViewController.h
@property (strong, nonatomic) UIImage *detailPhotoImage;
It's at PictureViewController where I am struggling to formulate the correct prepareForSegue method so that in my DetailPhotoViewController the same UIImage appears.
I've got a collection with picture that i can open when tapping the picture. This will pass the image to the PictureViewController, where it will be displayed in a fullscreen. On the PictureViewController I have got a Button in the Navigation bar that states Notes and which should pass me to DetailedPhotoViewController where the picture will be displayed smaller view.
Hopefully, this clarifies it a bit and thanks for the patience!
Upvotes: 0
Views: 367
Reputation: 131426
The other poster's advice is sound, but he posted his code in swift. Judging from the tags in your question, you're working in Objective-C.
In Objective-C the equivalent is to set define a property in your destination view controller:
@property (nonatomic, strong) UIImage* myImage
...and set that property in your prepareForSegue method (assuming you're using storyboards)
Upvotes: 1
Reputation: 1967
Please correct me if Im wrong... I think you mean you want to pass an UIImage presented in an UIImageView from one UIViewController to another one while pushing the new one into the UINavigationController stack...
All you have to do is to set up a UIImage property to your second ViewController like
var myImage:UIImage?
After that you can pass the UIImage from your old Controller to the second one like this, while pushing the second ViewController into your UINavigationControllers stack.
if let theCont:SecondViewController = storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as? SecondViewController {
theCont.myImage = UIImage(named: "imageFromOldController")
self.navigationController?.pushViewController(theCont, animated: true)
}
This is just one way to do it... I think it is the easiest to explain
Upvotes: 1