开发者

Objects return null after presentModalViewController

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 *over开发者_开发百科layImage = (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


I realized I was calling a action from a different class right after I dismissed the view. I simply made it a NSNotification and works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜