0

I Have three View controllers.

First UIViewController contain one UIImage, when I click "crop" button, go to second view controller I pass the image by push view controller, here I'am cropping my UIImage. In second UIViewController which is inherited from image editor Viewcontroller after cropping my image, clicking "done" button.

I need to pass the cropped image to another view controller where i am having share button to share the post.

Problem is when I am puishing the editted image to another view controller in which share button is present,image is not passing.

LML
  • 1,659
  • 12
  • 29
Aruna M
  • 386
  • 3
  • 12
  • 1
    Duplicate of http://stackoverflow.com/questions/14640456/how-to-passing-uiimage-from-one-view-controller-to-other-view-controller-when-us and http://stackoverflow.com/questions/19353248/passing-a-uiimage-from-one-view-controller-to-a-uitableviewcell – iPatel Mar 21 '14 at 06:49
  • how are you passing image to another view controller – Charan Giri Mar 21 '14 at 06:54
  • by using initwith image method i am passing the image from one view controller to another and also i am passing the editted image as imageview.image = v2.image – Aruna M Mar 21 '14 at 09:32

3 Answers3

1

You are saving the image in the Detail Controller before you make the push?

DetailController *detailVC=[[DetailController alloc]
                          initWithNibName:@"DetailController"
                          bundle:nil];

detailVC.image = self.image;

[self.navigationController pushViewController:detailVC animated:YES];
santibernaldo
  • 825
  • 1
  • 11
  • 26
  • but the same code i have tried it is not displaying the editted image in the share view controller i.e, in third view controller – Aruna M Mar 21 '14 at 09:30
  • Try to pass the info as well with Delegaton, Notifications or Key Value Coding – santibernaldo Mar 21 '14 at 09:34
  • one more thing that i like to say is the second view controller i am doing deep copy of image as an edited image so can u please go through the code – Aruna M Mar 21 '14 at 10:13
  • - (id)initWithImage:(UIImage *)image { self = [self init]; if (self){ originalImage = [image deepCopy]; NSLog(@"original image is %@",originalImage); } return self; } – Aruna M Mar 21 '14 at 10:13
  • the above original image is having the edited image and i need to send it to share view controller after clicking on share button i should share the image – Aruna M Mar 21 '14 at 10:15
  • for displaying the image in another view controller i am using this below code [_pickedImageView setImage:_clView.originalImage]; – Aruna M Mar 21 '14 at 10:18
1

Delegation

You implement the protocol on your View Controller

In Controller.h:

@class Controller;

@protocol ControllerDelegate <NSObject>

- (void)sendFrom:(Controller *)controller
                   image:(UIImage *)image;

@end

@interface Controller : UIViewController

@property (weak, nonatomic) NSObject <ControllerDelegate> * delegate;

@end

In Controller.m when you want send the image:

[self.delegate sendFrom:self
         image: self.image];

After on your Detail View Controller, don't forget to assign it as delegate of the Controller. And to implement the ControllerDelegate protocol. To do that:

In your DetailController.h implement the protocol. You can do that on your .m as well.

#import "Controller.h"

@interface DetailController : UIViewController <ControllerDelegate>

You keep a reference of the Controller in The Detail Controller

@property (nonatomic, strong) ViewController *controller;

And assign its delegate in the viewDidLoad of the Detail Controller. For example:

-(void)viewDidLoad:(BOOL)animated{

      [super viewDidLoad:animated];

      self.controller.delegate = self;
   }

Don't forget to implement the protocol method in your Detail View. Here you receive the image you passed from Controller and you save it in your Detail Controller UIImage property:

- (void)sendFrom:(Controller *)controller
                       image:(UIImage *)image{

   self.image = image;
}
santibernaldo
  • 825
  • 1
  • 11
  • 26
0

You can implement storyboard segue to your detail controller and use following sample code.

- (void)cropButtonClick:(id)sender
{
    [self performSegueWithIdentifier: @"MySegue" sender:sender];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"MySegue"]) {
        DetailController *detailVC = segue.destinationViewController;
        [detailVC setImage:self.image];
    }
}
Akki
  • 1,487
  • 14
  • 25