Move from Viewcontroller to another after image take - ios

OK, I am a NOOB with iPhone and have a simple question I assume. I have found a lot of help out there but am not sure what I am doing wrong. I simply want to take a photo with the camera then move to the next view controller after successful capture and place it in an image view. Got most of this code from here so thanks already but can not seem to get it to work, all different kinds of errors I do not understand. I think it must be that I am killing the view controller then trying to re-instantiate it but am a little lost Please Help.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (IBAction)TakePhoto:(id)sender{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
[self dismissViewControllerAnimated:YES completion:NULL];
NSString *submit = #"viewControllerSubmit";
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:submit bundle:nil];
UIViewController *vc = [mainstoryboard instantiateViewControllerWithIdentifier:submit];
[self presentViewController:vc animated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
As you can see I have tried a few things. I have tried searching for the errors but tried other things to no avail. Any assistance would be great, thanks in advance.
EDITED VERSION and FULL CODE BELOW HERE
====================================================================
OK, I am posting my full code. I can get the form to go from one to the next as I was simply calling the storyboard name wrong. However I can not get the image I take from the camera to show up on the next form. All I get is an empty ImageView without any errors. What am I missing? Please help been working on this for days and have researched a ton.
First View Controller .M File
#import "ViewController.h"
#import "ViewControllerSubmit.h"
#interface ViewController ()
#end
#implementation ViewController{
UIImage *newImage;
}
- (IBAction)TakePhoto:(id)sender{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil]; //nil from Null
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"ViewControllerSubmit"]){
ViewControllerSubmit *destViewController = segue.destinationViewController;
destViewController.theNewImage = newImage;
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
newImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:NULL];
NSString *submit = #"ViewControllerSubmit";
NSString *main = #"Main";
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:main bundle:nil];
UIViewController *vc = [mainstoryboard instantiateViewControllerWithIdentifier:submit];
[self presentViewController:vc animated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
First View Controller .H File
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>{
UIImagePickerController *picker;
}
#end
Second View Controller .M File
#import "ViewControllerSubmit.h"
#interface ViewControllerSubmit ()
#property (weak, nonatomic) IBOutlet UIImageView *_image;
#end
#implementation ViewControllerSubmit
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self._image.image = self.theNewImage;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Second View Controller .H File
#import "ViewController.h"
#interface ViewControllerSubmit : ViewController
#property (strong, nonatomic) UIImage *theNewImage;
#end
Again, no error, the camera comes up, it takes the picture and when I click 'Use Photo' the second View Controller pops up but the image view does not show the image captured.
What am I missing? Any help would be great and again please forgive the ignorance, I am new to iPhone.

You need to write navigation code in completion block...
Try below code,
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
[picker dismissViewControllerAnimated:YES completion:^{
NSString *submit = #"viewControllerSubmit";
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:submit bundle:nil];
UIViewController *vc = [mainstoryboard instantiateViewControllerWithIdentifier:submit];
[self presentViewController:vc animated:YES completion:nil];
}];
}

Related

Present View Controller not working with ios 9

Present view controller is not working with ios 9,
when I press the button it not redirected to present view controller.
Why this happens ?
I had tried the below code
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:#"Registration" bundle:nil] instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
I had also tried the below code
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Registration"
bundle:nil];
RegistrationViewController *add =
[storyboard instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:add animated:YES completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:add
animated:YES
completion:nil];
});
}];
Edit
My complete code here. I am using Xcode 7 and running it with ios 9
#import "LoginViewController.h"
#import "RegistrationViewController.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionRegistrationClicked:(id)sender
{
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:#"Registration" bundle:nil] instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
#end
Registration view controller
#import "RegistrationViewController.h"
#interface RegistrationViewController ()
#end
#implementation RegistrationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Make sure the presentedViewController is nil. If presentedViewController is not nil change the code to following.
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:#"Registration" bundle:nil] instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
if ([self presentedViewController]) {
[[self presentedViewController] dismissViewControllerAnimated:NO completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:viewController animated:YES completion:nil];
});
}];
} else {
[self presentViewController:viewController animated:YES completion:nil];
}
try viewDidAppear in
-(void)viewDidAppear:(BOOL)animated{
[self presentViewController:viewController animated:YES completion:nil];
}
Try the below code:
RegistrationViewController * viewController = [[self.storyboard instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];

How do i pass an UIImageView between view controllers?

I'm trying to choose an image from the camera roll in a view controller and then pass it/show that image in another view controller. Why doesn't the image view get passed?
When landing on FirstViewController i have a segue in the navigation bar to the SecondViewController.
//FirstViewController.h
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
#end
//FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
#interface FirstViewController () <SeconViewControllerDelegate>
#end
#implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark - SecondViewControllerDelegate
- (void)didDismissWithImageView:(UIImageView *)imageView
{
self.imageView = imageView;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"addPhoto"]) {
SecondViewController *secondVC = segue.destinationViewController;
secondVC.delegate = self;
}
}
#end
//SecondViewController.h
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#protocol PhotoPickerDelegate <NSObject>
- (void)didDismissWithImageView:(UIImageView *)imageView;
#end
#interface SecondViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (weak, nonatomic) id<PhotoPickerDelegate> delegate;
#property (strong, nonatomic) UIImageView *imageView;
- (IBAction)useCameraRoll:(id)sender;
#end
//SecondViewController.m
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)useCameraRoll:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
}
if ([self.delegate respondsToSelector:#selector(didDismissWithImageView:)]) {
[self.delegate didDismissWithImageView:_imageView];
}
[self.navigationController popViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
If its just an image we are talking about here then lets make a property for the image.
#property (nonatomic, strong) UIImage *imageIWant;
Once we have our image property, we can set the image that you want by either calling [UIImage imageWithData:imageData]; or set it from a file within our Plist. I do not recommend saving an imageView and passing that view among controllers because within our MVC model, the view and the model are separate. At the end of the day, its an image within the model that you want not a view element.

How to keep an image in a UIImageView when switching between multiple UIViewControllers

I'm trying to write an extremely basic Xcode (ver. 5) project application for the iPhone5 that loads an image from the photo library into an UIImageView in the start up UIViewController and keeps that image in the UIImageView (or returns it) when switching between other view controller panels. The problem I am having is that when I return from other UIViewController windows to the main view controller with my UIImageView, the loaded image that was previously displayed is gone and I end up having to reload it into the UIImageView. How can I make this behave where the image remains in the UIImageView after I return from other UIViewController windows?
Implementation File...
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (IBAction)btnClick:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
modBuffer = info[UIImagePickerControllerEditedImage];
self.imageView.image = modBuffer;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
Header file...
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImage* modBuffer;
}
#property (strong, nonatomic) IBOutlet UIImageView* imageView;
- (IBAction)btnClicked:(id)sender;
I think you need to make property for UIImage (nonatomic,retain) and then u should try to do it.

Displaying image in a new view controllers UIImageView

I'll post my code first and then I'll explain the problem
RootViewController.h its called SpViewController.h
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "secondViewController.h"
#interface spViewController : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate>
#property BOOL newMedia;
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
#property (strong, nonatomic) spViewController *secondViewController;
#property (strong, nonatomic) UIImageView *image;
#property (strong, nonatomic) UIImage *myImage;
- (IBAction)useCamera:(id)sender;
- (IBAction)useCameraRoll:(id)sender;
#end
spViewController.m
#import "spViewController.h"
#import "secondViewController.h"
#interface spViewController ()
#end
#implementation spViewController
- (IBAction)backtohome:(UIStoryboardSegue *)unwindSegue
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)useCamera:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = YES;
}
}
- (IBAction)useCameraRoll:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = NO;
}
}
//image picker delegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; self.myImage = chosenImage;
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self performSelector:#selector(myMethod:) withObject:info afterDelay:0.1];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
}
}
-(void)myMethod:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"Perform segue");
[self performSegueWithIdentifier:#"Picture Unwind Segue" sender:self];
}];
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
//cancel delegate
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier]isEqualToString:#"Picture Unwind Segue"]) {
secondViewController *destinationViewController = [segue destinationViewController];
destinationViewController.imageView.image = self.myImage;
}
}
#end
secondViewController.h
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "spViewController.h"
#interface secondViewController : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate>
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
#property (strong, nonatomic) UIImage *myImage;
#property (strong, nonatomic) UIImageView *image;
#end
secondViewController.m
#import "secondViewController.h"
#import "spViewController.h"
#interface secondViewController ()
#end
#implementation secondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.imageView.image = self.myImage;
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
So the problem I'm having is, I can't get the image that has just been selected in the UIImagePickerController to be displayed in the UIImageView, my ImagePickerController was initiated by a button in my previous view controller "spViewController" (rootViewController) I am using Storyboards, I thought if I put in the UIImageView then connected it using an outlet reference it would display there, this doesn't seem to be the case though. If I put the UIImageView in the first view controller and do the same it will display the image but thats not where I want it to go.
Thank you for any help
To fix my problem i decided to save the image and call on it later heres the code i put into my secondViewController.m
{NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filepathJPG = [docsPath stringByAppendingPathComponent:#"imagefile.jpg"];
UIImage *img = [UIImage imageWithContentsOfFile: filepathJPG];
if (img != nil) {
// assign the image to the imageview,
_imageView.image = img;
// Optionally adjust the size
BOOL adjustToSmallSize = YES;
CGRect smallSize = (CGRect){0,0,100,100};
if (adjustToSmallSize) {
_imageView.bounds = smallSize;
}
}
I hope this can help others that have the same problem.
So according to your code , you are setting the property of myImage which is an instance of UIImage from the RootViewController.
so your just passing the data of the image , But your not setting your imageView.image property to the passed image value.
So a possible fix would be to set
imageView.image = myImage in viewDidLoad
or
you can directly access the imageView property from the perform prepare for segue method in the RootViewController and set its image property.
I hope this helps .
Cheers
You can declare a property in AppDelegate class and access it across all controllers using appdelegate shared instance

How to pass image, from uiimagepickercontroller, into another scene's uiimageview

How do I save a UIImagePickerController camera image so I can send to CreateViewController scene's UIImageView?
HomeViewController(scene 1) has a button that loads UIImagePickerController and returns with an image from the camera. CreateViewController(scene 2) has an empty UIImageView.
HomeViewController.h
#import "CreateViewController.h"
#interface HomeViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (strong, nonatomic) UIImagePickerController *imagePicker;
#property(nonatomic, retain) UIImage *myImage;
- (IBAction)cameraImage:(id)sender;
HomeViewController.m
#implementation HomeViewController
#synthesize imagePicker, myImage;
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ( [segue.identifier isEqualToString:#"create"]) {
CreateViewController *cvc = [segue destinationViewController];
UIImage *image = myImage;
cvc.myImage = image;
}
}
//Camera button action
- (IBAction)cameraImage:(id)sender{
//UIImagePickerController space in memory
imagePicker = [[UIImagePickerController alloc]init];
//Set the delegate
imagePicker.delegate = self;
//Set the sourceType
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Show Image Picker UI
[self presentViewController:imagePicker animated:YES completion:^{}];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {
self.myImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^{}];
[self performSegueWithIdentifier:#"create" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
CreateViewController.h
#property (strong, nonatomic) IBOutlet UIImageView *bgImage;
#property(nonatomic, retain) UIImage *myImage;
CreateViewController.m
#implementation CreateViewController
#synthesize bgImage, myImage;
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = myImage;
[bgImage setImage:image];
}
Download sample code here; http://code-blind.com/ios6-camera-picture-to-another-scenes-uiimageview/
Using a segue is not mandatory if you are instanciating the controller programmatically.
The easiest way to achieve that is something like
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage * pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
DisplayViewController * controller = [DisplayViewController new];
controller.imageView.image = pickedImage;
[self.navigationController pushViewController:controller animated:YES];
}
If you want to use a segue you need to manually invoke it by doing
[self performSegueWithIdentifier:#"your-segue-name" sender:self];
then you can use an ivar in your HomeViewController to store the pickedImage and pass it to your destinationViewController.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DisplayViewController * controller = (DisplayViewController *)segue.destinationViewController;
controller.imageView.image = _pickedImage;
}
where _pickedImage is the ivar where you stored the image after it has been picked.
On ur first view
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
CreateViewController* sI = [self.storyboard instantiateViewControllerWithIdentifier:#"XXXXX"];
sI.myImage = image;
}
XXXXX is identifier of view.
First you have to be sure that your delegate method is called and that you have the image.
Next, store the image to a property:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
self.takenImage = image; // assuming you have declared #property(nonatomic, strong) UIImage *takenImage;
[picker dismissViewControllerAnimated:YES completion:^{
[self performSegueWithIdentifier:#"my-segue" sender:self];
}];
}
After that, this method's being called:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// you need to set the picked image to the controller:
DisplayViewController *controller; // get the controller
controller.image = self.takenImage;
}
in this code:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if( i ==1)
{
[self dismissViewControllerAnimated:YES completion:^
{
Second_ViewController*secondview=[[UIStoryboard storyboardWithName:#"Main" bundle:nil]instantiateViewControllerWithIdentifier:#"Second_ViewController"];
secondview.bb_image=image;
[[NSUserDefaults standardUserDefaults ]setInteger:0 forKey:#"123"];
[[self navigationController] pushViewController:secondview animated:YES];
}];
}

Resources