Issue with code sdk 3.1.3

Hi all,

I am having a bit of an issue with some code.
I basically have 2 actions

using the UIImagePickerController.

Action 1 is:

imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

The above code opens the image library

Action 2 is:

imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

The above code opens the camera

The code works fine BUT I cannot get both the work, each on a different action assigned to a button.

Here is the whole code below:

#import "PickerViewController.h"

@implementation PickerViewController

@synthesize imgPicker;

- (void)viewDidLoad {
      self.imgPicker = [[UIImagePickerController alloc] init];
      self.imgPicker.allowsImageEditing = YES;
      self.imgPicker.delegate = self;            

- (IBAction)grabImage {
      imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
      [self presentModalViewController:self.imgPicker animated:YES];


- (IBAction)takeImage {
      imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
      [self presentModalViewController:self.imgPicker animated:YES];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
      image.image = img;      
      [[picker parentViewController] dismissModalViewControllerAnimated:YES];
      // need to show the upload image button now
      upload.hidden = NO;



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I've not tried this scenario, but it should work (in case you have enough memory):
"Prior to running the picker interface, set this value to the desired source type. The specified source type must be available and an exception is thrown if it is not. If you change this property while the picker is visible, the picker interface changes to match the new value in this property."

Here are two nice tutorials

In the last link, in the comment after the article, you will see the code for the camera and the switch from the camera to the photo gallery.

Here is a nice tutorial or FAQ:
UIImagePickerController, UIImage, Memory and More!

ST3VOAuthor Commented:
Hi and thanks from your reply. Thinks are good but it's not a memory issue. I have 2 actions and whichever I run first retains. For example if I click on grabimage first the 2 buttons retain the sourcetype and vica versa, so I need to sort that out.
Try to switch to UIImagePickerControllerSourceTypeSavedPhotosAlbum.

For a test purpose (or, maybe, it will good for you), I'd try to re-create the UIImagePickerController - release and alloc again.

Actually the code taking an image is here:

if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[[self navigationController] presentModalViewController:picker animated:YES];
[picker release];

If you will read this:

Here is an interesting thread:

P.S. About the memory issue:
Memory usage in UIImagePickerController

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Seems like here is a simple app that does exactly what you need:
Picking Images with the iPhone SDK UIImagePickerController
ST3VOAuthor Commented:
Hmmm...looks promising thx. Let me check it out and get back to you when I get home. Thx a lot!
ST3VOAuthor Commented:
Downloaded the dmg file and extracted the code and opened it and tried to run it but it give me errors so I cannot check out that download provided on the link. Will continue looking at the code and see If I can figuare out a fix. Will look at the links you provided.
ST3VOAuthor Commented:
Thanks :o)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.