Reputation: 1
I want to pass one Image that i take from gallery or camera and i want it to pass on next view.
I do it by the code.
PhotoDocumentViewController *objectPhotoDocument = [[PhotoDocumentViewController alloc]initWithNibName:@"PhotoDocumentViewController" bundle:nil];
[objectPhotoDocument.imgSelectedPhoto setImage:finalImage];
[self.navigationController pushViewController:objectPhotoDocument animated:YES];
Here imgSelectedPhoto is the UIImageView that i declared on next view(PhotoDocumentViewController).
But when it pushed next view. Image can not be displayed i don't know what is the problem. Please help me.
Upvotes: 0
Views: 500
Reputation: 842
Create a property for UIImage
in PhotoDocumentViewController
as:
@property (nonatomic, strong) UIImage *myImage
And set it with:
[objectPhotoDocument setMyImage:finalImage];
before pushing your objectPhotoDocument
.
This way you will have a strong pointer to the UIImage
object. And in viewDidLoad
method of PhotoDocumentViewController
set this object to your UIImageView
.
[self.imgSelectedPhoto setImage:self.myImage];
Upvotes: 0
Reputation: 3432
You need to set the properties of view and subviews after the view controller finished loading the views, i.e. inside viewDidLoad
function. Something like:
PhotoDocumentViewController *objectPhotoDocument = [[PhotoDocumentViewController alloc]initWithNibName:@"PhotoDocumentViewController" bundle:nil];
objectPhotoDocument.imageToSend = finalImage;
[self.navigationController pushViewController:objectPhotoDocument animated:YES];
PhotoDocumentViewController.h
@interface PhotoDocumentViewController : UIViewController
...
@property (nonatomic, strong) UIImage *imageToSend;
@end
PhotoDocumentViewController.m
- (void)viewDidLoad
{
...
imgSelectedPhoto.image = self.imageToSend;
...
}
Upvotes: 1