?
Solved

Issue with code sdk 3.1.3

Posted on 2010-04-03
7
Medium Priority
?
458 Views
Last Modified: 2013-11-25
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




0
Comment
Question by:ST3VO
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 29631382
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
 

Author Comment

by:ST3VO
ID: 29642246
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
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 2000 total points
ID: 29644950
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 29645222
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
 

Author Comment

by:ST3VO
ID: 29647495
Hmmm...looks promising thx. Let me check it out and get back to you when I get home. Thx a lot!
0
 

Author Comment

by:ST3VO
ID: 29688765
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
 

Author Closing Comment

by:ST3VO
ID: 31710623
Thanks :o)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question