0

My UIImagePickerController freezes and the camera closes when the button to flip the camera from front to back is pressed. This is how I initialize the image picker controller object within the project (the rest of the code was ommitted) from the methods as it is irrelevant to the UIimagepickercontroller object.

//In my .h file 
UIImagePickerController * imgPicker;

//in my .m file
-(void)viewDidLoad {

imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsEditing = YES;

}

-(void) takePicture {

imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imgPicker animated:YES completion:NULL];

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

masterImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

if(masterImage.image == nil) {

    masterImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

}

[self dismissModalViewControllerAnimated:YES];

}

-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{

[self dismissModalViewControllerAnimated:YES];

}

-(void) releaseOutlets {

[imgPicker release];

}
Andrew
  • 63
  • 1
  • 7

2 Answers2

1

Just for rule, change your code. Instead of:

UIImagePickerController * imgPicker;

Write in your .h file:

@property (nonatomic, strong) UIImagePickerController * imgPicker;

than synthesize it in your .m file:

imgPicker = _imgPicker;

and next every call to this property call with self.

edzio27
  • 4,126
  • 7
  • 33
  • 48
-2
  • first of all, you should not alloc init in viewdidload method. Do all ur allocations in -init method.
  • add property as suggested by edzio27.
  • test again

if problem persists: - check if u are "receiving memory warning". In case of memory warning ur viewdidload method is called again. In case u keep ur alloc init in that method u will be creating new instance everytime.

We faced a similar issue with MPMoviePlayerController. not sure if u have the same issue.

Anup
  • 42
  • 5
  • Pretty sure that's not true. Nothing wrong with init in vDL. And vDL won't be called on memory warning unless it triggers your app level code to manual reload the VC. – Hari Honor Sep 09 '14 at 09:39