Take the 2-minute tour ×

Alright, this has been driving me insane for the last few days. I hope this is an easy fix. I am trying to access my UIImageView.image so I can replace it later.

With only the needed code here it is:

I first create an imageView for each time a user clicks on a photo in their Library.

// .h
@property (strong,nonatomic) UIImage *doneImage;
@property (strong,nonatomic) UIImageView *editImage;

// .m
@synthesize doneImage;
@synthesize editImage;

UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, widthOfImage, heightOfImage)];
imgView.image = originalImage;
imgView.userInteractionEnabled = YES;
[self.mainView addSubview:imgView];

// I add gestures
longPress.minimumPressDuration = 1;
longPress.numberOfTouchesRequired = 1;
[imgView addGestureRecognizer:longPress];

When someone clicks holds down on one of those images this pops up

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {

editImage = (UIImageView*)recognizer.view; // I declare what editImage is and now have access to what imageView is being interacted with.
doneImage = editImage.image; // I then get the image of that for later use.

if(UIGestureRecognizerStateBegan == recognizer.state) {

        popoverEditor = [[UIPopoverController alloc] initWithContentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"popupEditor"]];
[popoverEditor presentPopoverFromRect:editImage.bounds inView:editImage permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


This pops up a menu with 4 buttons. I then have an IBAction that tries to fire up the editing part.

- (IBAction)effectsEditorButton:(id)sender { 

// editImage is my imageView

if (editImage == nil) {
    NSLog(@"imageView was nil wtf");
} else {
    [self performSelector:@selector(editImageWithEffects:)];

My image view is ALWAYS nil. I need to get a reference to that somehow. I've tried tags but I can't seem to get them to hold their value once I get to this point.

Any help would be very much Appreciated. Thanks!

share|improve this question
add comment

1 Answer

Are you leaving out code? Based on what you have here, editImage will always be null because it isn't declared anywhere (perhaps something in Interface Builder that we can't see?).

You need a way to link back into your view controller from your popover. Popular ways to do this are to use a completion block when returning from your popover controller, or setting your "main" VC as a weak property on the popover.

share|improve this answer
I updated my declarations. I will look into Completion Blocks a little later on. Thanks for the response. –  NewGuyIThink Oct 17 '12 at 21:12
Is effectsEditorButton a function on the same class where editImage is declared? I would think that this would be on the popupEditor PopoverController, which won't have an editImage property (unless I'm missing something obvious). –  Robert Zahm Oct 17 '12 at 23:04
I have everything on the same class right now. Just trying to figure it out. –  NewGuyIThink Oct 17 '12 at 23:52
My guess is that your popover event handler isn't pointing at the same instance of your class. I would suggest adding a delegate to "popupEditor," and set your class to this property after creating "popupEditor." Then you can access the "editImage" property through the delegate. –  Robert Zahm Oct 18 '12 at 0:35
add comment

Your Answer


