How to Save a imagepicker with textview Data in iOS - ios

I have a UITextView, image picker and submit UIButton in a view. I want to save the data together, but since the imagePickerController uses a delegate method, it is called independently of when data is entered in the textview.
Should I temporarily save the image from the didFinishPickingMediaWithInfo method and then retrieve it when the submit button is clicked?
If so, how do I do this?
If not, how to I save the textview and image data at the same time?

Should I temporarily save the image from the didFinishPickingMediaWithInfo method and then retrieve it when the submit button is clicked?
Yes.
If so, how do I do this?
#property (nonatomic) UIImage *lastSelectedImage;
- (void)imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.lastSelectedImage = image;
[thePicker dismissViewControllerAnimated:YES completion:nil]
}
- (void) buttonPressed:(id)sender {
// do something with self.myTextView.text and self.lastSelectedImage
}

Related

call image picker controller delegate method from another method

I am using Image picker Controller to take pictures and save them into database. I have this method to to get the image taken by the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
This method is getting called automatically as it is delegated as self. I tried to call this ,when I click a button,but I couldn't get the image . It is showing me null.Here is the method I am calling the picker controller delegate method.
- (IBAction)save_Image:(id)sender {
UIImagePickerController *saveDelegate;
NSDictionary *infoDelegate;
[self imagePickerController:(saveDelegate) didFinishPickingMediaWithInfo:(infoDelegate)];
UIImage *chosenImage = infoDelegate[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
//here i couldn't get the image. I am getting null
}
Is there any possible way that I can get the image by calling that method from my own method?
If you want to inform others of when a user picks an image, this is a perfect place to use notifications.
static NSString* const ImagePickerDidFinishPickingPhotoNotification = #"ImagePickerDidFinishPickingPhotoNotification";
#implementation MyViewController
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[[NSNotificationCenter defaultCenter] postNotificationName:ImagePickerDidFinishPickingPhotoNotification
object:picker
userInfo:info];
}
#end

UIImage displaying duplicate images for two UImages

I have a UImage view that opens and you can take a picture with it and view it in the uiimageview. But I added another image view and copied the code and now the image shows up the same as the second one. I believe it may have something to do with the '[UIImagePickerControllerOriginalImage];'
- (void)imagePickerController:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
// Get the image and store it in the image view
image = info[UIImagePickerControllerOriginalImage];
self.personimgThumbNail.image = image;
}
- (void)imagePickerControllertwo:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
// Get the image and store it in the image view
imagetwo = info[UIImagePickerControllerOriginalImage];
self.personimgThumbNailtwo.image = imagetwo;
}
The appropriate delegate method which you're attempting to use is imagePickerController:didFinishPickingMediaWithInfo:.
Your second method, imagePickerControllertwo:didFinishPickingMediaWithInfo:, is not a delegate method and will not be called automatically.
If you put in some NSLog statements, you'll probably find that the first method is called twice (as expected, because that's the correct delegate method). If you want to do different things for each picker, look at the value of the picker argument; that's what it's there for.

UIImagePickerViewController Freezes in iOS

I am using static librrary and there is one class inside it that uses UIImagePickerViewController. I have set the delegate to it and written didFinishPickingMediaWithInfo: method within that class. What I want is to open front camera, capture the image when user clicks it and then save it to Photo Albums. What is happening with my code is that UIImagePickerController loads the camera and it saves the photo after capturing when I click on "Use Photo" button. But after that, it freezes but not crashes. I can't click anywhere after that. Any help appreciated. Thanks
// CODE IN LIBRARY
+ (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* photo = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *data = UIImagePNGRepresentation(photo);
photo = [UIImage imageWithCGImage:[UIImage imageWithData:data].CGImage
scale:photo.scale
orientation:photo.imageOrientation];
UIImageWriteToSavedPhotosAlbum(photo, self, nil, nil);
// TRIED ALL OF THE BELOW BUT NOTHING WORKS FOR ME
[picker dismissViewControllerAnimated:NO completion:nil];
// [picker dismissModalViewControllerAnimated:YES];
[picker.view.superview removeFromSuperview];
// [picker release];
// picker=nil;
}
Your method shouldn't be static - remove the '+' and replace it with '-'.
Also, in the method you do
[picker.view.superview removeFromSuperview];
I'm not sure that's what you want to do !
So your code becomes :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
...
}

selecting image for multiple image view from cam or library

I have 3 Image views on my view controller (Purpose Before ,During, After) .
i need to select images for each of view respectively .
the didicated method for this task is :
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image;
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[_imgView setImage:image];
[self dismissViewControllerAnimated:YES completion:NULL];
}
but how to notify this method about which button has called the image picker and to select/display the image on view respectively .
Add a "private" (yes I know no such thing) ivar to hold a reference to the selectedImageView
#interface MyViewController ()
#property (nonatomic, strong) UIImageView *selectedImageView;
#end
Then when the imageView is selected use this new ivar to keep a reference to the currently active imageView
- (void)imageViewTapped:(id)sender
{
// This assumes the use of a gesture recognizer but you can substitute your usual method
// of detecting the imageView that you want to edit.
self.selectedImageView = [sender view];
}
Now your delegate can look like this
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.selectedImageView.image = info[UIImagePickerControllerOriginalImage];
self.selectedImageView = nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
On a class level take a variable that holds the reference of the imageview.
When you are tapping the image, store the tapped imageview's reference into this variable.
Into imagepicker delegate method, use this variable to set image.

How to detect UIImagePickerController Preview state?

I use standart image picker to make some camera photo.
When user makes photo image picker shows him the Preview screen with 2 buttons "Retake" and "Use".
How to detect that Preview screen is active now or "Retake" button pressed? Is it possible ? Are the useful properties or events? Something like when image source is library the is property - allows editing, which shows similar screen .
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
A bit after the fact, but maybe someone is still seeking this answer like I was. If you want continue using the native camera controls, you can check the subviews of the ImagePickerController to determine if the post-record view is showing.
BOOL videoTaken = NO;
for (UIView *aView in self.imagePickerController.view.subviews[0].subviews[0].subviews[0].subviews)
{
if ([aView isKindOfClass:NSClassFromString(#"PLTileContainerView")])
{
videoTaken = YES;
break;
}
}
The "PLTileContainerView" is the subview that contains the editing slider that lets you view your video frame by frame, so if it's present, that means your video has already recorded.
For use:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:NO];
NSString *type = [info objectForKey:#"UIImagePickerControllerMediaType"];
if ([type isEqualToString:#"public.movie"]) {
} else {
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
}
For Cancel you don't have a way of detecting it (other than subclassing UIImagePickerController, which may be prohibited, or other way that I'm not aware), but for sure the second cancel is detectable :
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}

Resources