0

I create an app with custom camera picker, and i try to pass the overlay image from a class to other class, below more infos about my code:

Using Storyboard:

UICollectionView load a .plist with images from web then using Segue Identify to pass the information to another View.

In My second view i see my chose image, share buttons and Camera button, if i tap camera button loading mu Custom camera view in a separate .xib, her i want to pass my first chose image to a UIImageView in a .xib

Here My code:

The process of 3 controllers is:

First controller from a UITableView

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

    if([@"goToShare" isEqualToString:segue.identifier]) {
        NSIndexPath *index = [self.tableView indexPathForCell:sender];
        [[segue destinationViewController] setImgSelected:(self.loadImage)[index.row]];
    }

}

Here set my image in to NSMutableDictionary *imgSelected;

In my second controller i get the information in to:

- (void)viewDidLoad {

    NSString *url = (self.imgSelected)[@"image"];
    NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
    imageViewPick.image = [[UIImage alloc] initWithData:data];

    [super viewDidLoad];
}

Now i want to pass from second controller imageViewPick.image the same image in the third controller in to my imageOverlay.image

When tap on Camera Button and load cover vertical my .xib:

- (IBAction)getPhoto:(id) sender {

    CustomCameraViewController *camController = [[CustomCameraView alloc] initWithNibName:@"CustomCameraView" bundle:nil];
    camController.delegate = self;

    [self presentViewController:camController animated:YES completion:^{

    }];
}

I try to get imageViewPick.image with:

MyFirstView *imgDelegate= (MyFirstView  *)[[UIApplication sharedApplication] delegate];
self.imageOverLay.image = imgDelegate.imageViewPick.image;

But not working and the app crash.

Any idea how to pass the information from firstClass.m to a secondClass.m ?

BlackSheep
  • 1,087
  • 12
  • 29

2 Answers2

1

The initWithNibName method returns the UIViewController, let's call an instance of MySecondViewController. Add a UIImage property to the MySecondViewController. Then, once the instance of MySecondViewController is initialized, set the UIImage property to the image you want. E.g.:

In MySecondViewController.h:

...
@property (nonatomic, weak)UIImage *overlayImage;
...

In MyFirstView.m:

...
MySecondViewController *secondViewController = [MySecondViewController initWthNibName:<insert name of xib> bundle:<probably nil>];
secondViewController.overlayImage = self.imageOverlay.image;
...

You can then access the overlay image in the MySecondViewController with self.overlayImage

bobnoble
  • 5,794
  • 3
  • 25
  • 32
0

In <- (IBAction)getPhoto:(id) sender> you have to set camController.imageOverLAy.image = self.imageViewPick.image; before present camController. Hope it will helps you!

[[UIApplication sharedApplication] delegate] returns a pointer to the AppDelegate.
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Meeshoo
  • 129
  • 11
  • If you have 3 controllers and want to pass an information from first controller to the third, you need initially to pass that information do the second controller and then when you will push the third controller you have to pass the information from the second controller to the third one. (This means you have to make another property in second view to store the information you want to pass) – Meeshoo Jul 11 '14 at 11:13
  • No i want to pass the information only from second controller to a third – BlackSheep Jul 11 '14 at 11:18
  • You can create a public instance variable in third view controller and set it from second view controller, before presenting third view controller. This is most simple way to pass data between two view controllers. – Dileep Jul 11 '14 at 11:20
  • Ok. Then in second controller make a public property @property (strong, nonatomic) MyFirstController *parentController; (don't forget to import your first controller). In first controller , before presenting the second controller, set secondController.parentController = self; Then, when pushing the third controller in second controller you just have to set: thirdController.imageOverLay.image = self.parentController.imageViewPick.image; – Meeshoo Jul 11 '14 at 11:20