Hi i am getting image from gallery by UIImagePickerController and shows on my view controller, i have textfield also when i enter text in textfield my image disappear. Please help me what is issue with this. my UIImagePickerController delegate method is
-(IBAction)btnBackAction:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)imageactoin:(id)sender{
UIImagePickerController *pickerController = [[UIImagePickerController alloc]
init];
pickerController.delegate = self;
[self presentModalViewController:pickerController animated:YES];
}
#pragma mark UIImagePickerControllerDelegate
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
self.imageView.image=image;
[self dismissModalViewControllerAnimated:YES];
}
#end
please help me whats issue that my image not disappear by selecting another event like textfield.
The below delegate method is deprecated from iOS 3.0
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
You have to use this one,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Related
I created a simple button within my Main-View Controller. After calling imagePickerController and taking a picture, I want to redirect the user to the next view controller to continue processing the image. Somehow it always returns to my main window.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
// Code here to support video if enabled
}
}
for that you have to push your view Like
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
...
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
...
YourImgViewController *imgProcessing = [[YourImgViewController alloc] initWithNibName:#"YourImgViewController" bundle:nil];
imgProcessing.selectedImageView.image = image;
[self.navigationController pushViewController:imgProcessing animated:YES];
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
// Code here to support video if enabled
}
}
very simple!
you can find more hint on this link http://www.edumobile.org/iphone/how-to-make-an-app-2/tutorial-on-image-picker-controller-in-iphone/
I am having a problem with presenting a view controller while another one is already presented.
In my app, I present a UIImagePickerController, which after selecting an image (either from the library or through the device's camera) should return to another view controller.
For example, let's say you clicked a camera button which launches the camera, and after you take a picture, the camera slides down, but the view you see is not the one with the camera button but a view which lets you edit the metadata of the image.
Does anyone know a way to accomplish this task?
Thanks ahead, iLyrical.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:NO];
NewViewController *viewController = [[NewViewController alloc] init];
viewController.image = image;
[self presentModalViewController:viewController animated:NO];
}
And if you can use iOS 5.0 or newer:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissViewControllerAnimated:YES completion:^(){
NewViewController *viewController = [[NewViewController alloc] init];
viewController.image = image;
[self presentViewController:viewController animated:NO completion:nil];
}];
}
Check Apple's doc on UIViewController Class Reference
If you are able to initialize the final viewController before presenting UIImagePickerController, you can try:
Initialize final viewController
Set it hidden or its view's alpha=0 and push non-animated
Present imagePicker viewController
Set the final viewController non-hidden
Dismiss modal viewController
I'm trying to make my app switch to another view when the user finish selecting an image, but what happen is when the user finish picking the image, it dismisses the picker and comes back to the same view.
Here's my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}
That happens because you're dismissing the picker modal view controller with animation and presenting the new view controller right away. You can only present a new modal view controller after the previous one has been dismissed.
A solution would be to dismiss the picker modal without animation :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:NO];
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}
Another solution (that works only on iOS 5) is to use the dismissViewControllerAnimated: completion: method :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissViewControllerAnimated:YES completion:^(){
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}];
}
I'm able to call the modal view controller for the image picker, pick the image, and crop it, but when I tap 'done' it doesn't do anything, it just hangs with the done button grayed out.
There are no errors, but the function is called.
- (void)viewDidLoad
{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = YES;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
userImage.image = img;
uploadButton.hidden = NO;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
NSLog(#"called");
}
- (IBAction)getImage:(id)sender {
[self presentModalViewController:self.imgPicker animated:YES];
}
Replace
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
with:
[self dismissModalViewControllerAnimated:YES];
I am using UIimagepickercontroller to browse or take a photo and display it on a subview.
-(IBAction) getPhoto:(id) sender {
secondView1 = [[secondView alloc]
initWithNibName:#"secondView"
bundle:nil];
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
[self.view addSubview:secondView1.view];
}
This works fine for SourceTypeSavedPhotoAlbum, but if I use camera, the secondview1.view does not show. Instead it only shows the original view.
This is my delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
secondView1.imageView.image = [info
objectForKey:#"UIImagePickerControllerOriginalImage"];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
Thank you for any help!
I finally found out that I should do:
secondView1 = [[secondView alloc]
initWithNibName:#"secondView"
bundle:nil];
self.view addSubview:secondView1.view];
in the delegate function.
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
...
}
Otherwise, the addsubview could be called before the image picker finishes picking an image. Now understand better about how the code flows and the delegate functions.