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;
      

}

@end




ST3VOAsked:
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.

pgnatyukCommented:
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."
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

Here are two nice tutorials
http://www.zimbio.com/iPhone/articles/1109/Picking+Images+iPhone+SDK+UIImagePickerController
http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/

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!
http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

0
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.
Thx
0
pgnatyukCommented:
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])
    return;
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[[self navigationController] presentModalViewController:picker animated:YES];
[picker release];

If you will read this: http://chris-software.com/index.php/2009/04/29/loading-images/

Here is an interesting thread:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/21440-imagepickercontroller-wont-return-camera-photo-will-return-album-photo.html#post96638

P.S. About the memory issue:
Memory usage in UIImagePickerController
http://blog.airsource.co.uk/index.php/2008/11/12/memory-usage-in-uiimagepickercontroller/
0

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.

pgnatyukCommented:
Seems like here is a simple app that does exactly what you need:
Picking Images with the iPhone SDK UIImagePickerController
http://trailsinthesand.com/picking-images-with-the-iphone-sdk-uiimagepickercontroller/
0
ST3VOAuthor Commented:
Hmmm...looks promising thx. Let me check it out and get back to you when I get home. Thx a lot!
0
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.
0
ST3VOAuthor Commented:
Thanks :o)
0
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
C

From novice to tech pro — start learning today.