I’m having a problem setting an image. I have a delegate telling me when an image is taken from the imagePickerController. It sends it to the owner controller, and then I try to set the image on another controller. It all seems like it should be working… but whenever I the view shows up, the image isn’t there. Here’s the code:
// this gets called when an image has been chosen from the library or taken from the camera
// it is in the viewController in charge of grabbing an image (.m file)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
if(self.delegate)
{
[self.delegate didAcquirePicture:image];
}
}
//This is in the controller .m file
- (void)didAcquirePicture:(UIImage *)picture
{
if(picture != Nil)
{
self.photoEditView = [[PhotoEditViewController alloc] init];
[self.photoPicker.imagePickerController dismissModalViewControllerAnimated:NO];
[self.photoEditView.imageView setImage:picture];
[self presentModalViewController: self.photoEditView animated:NO];
}
}
//this is the photoEditViewController .h
#import <UIKit/UIKit.h>
@class PhotoEditViewController;
@protocol PhotoEditViewControllerDelegate
@end
@interface PhotoEditViewController : UIViewController {
IBOutlet UIImageView *imageView;
}
@property (retain) UIImageView *imageView;
@end
//this is the photoEditView .m file
#import "PhotoEditViewController.h"
@implementation PhotoEditViewController
@synthesize imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc {
[super dealloc];
[imageView dealloc];
}
@end
FIGURED OUT THE PROBLEM
It turns out that my image was being deallocated before the view completely loaded and control was given back to the event loop. It was a timing problem, and I was stupid not to see it. So, I made a UIImage variable in my .h file called tempImage, then I just put this in -(void)viewDidLoad:
This is what my didAcquirePicture method looks like now:
I’m basically just saving the image, then when I KNOW the view is loaded, I set the image in my viewDidLoad. Thanks everyone for helping me arrive at the final answer!