Objects return null after presentModalViewController

advertisements

After showing a camera, my objects return null:

Here's how I show my UIImagePickerController (I initialize it before):

[self presentModalViewController:pickerOne animated:NO];

I add a object in my scrollView like this,

UIImageView *overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black_overlay.png"]];
[overlay setFrame:CGRectMake(((columnCount-1)*100)+((columnCount-1)*5)+5 ,((rowCount-1)*100)+((rowCount-1)*5)+11, 100, 100)];
[overlay.layer setCornerRadius:8.0];
[overlay.layer setMasksToBounds:YES];
[overlay setTag:12];
[theImageViewer addSubview:overlay];

And access it like this (after the camera has been closed):

UIImageView *overlayImage = (UIImageView*)[theImageViewer viewWithTag:[[arrayOverlays objectAtIndex:[arrayIds indexOfObject:imageThumbnail]] intValue]];
NSLog(@"OverlayImage: %@",[arrayOverlays objectAtIndex:[arrayIds indexOfObject:imageThumbnail]]);

And I get: Real overlayImage, (null)

Please help! Thanks.


  1. The pickerOne must be a property inside your current ViewController.
  2. Your current ViewController must conform to protocol of UIImagePickerControllerDelegate.
  3. In the imagePickerController:didFinishPickingMediaWithInfo: implementation from the delegate you'll get the image object and dismiss the modalViewController.

That should do the trick.

Edit: just found a tutorial that explains this in detail:

http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/

Note:imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo is deprecated in iOS 3.0