views:

259

answers:

2

Hi All. I'm soooooo close to finally finishing my first app to put in the store. Everything works just fine and memory leaks are almost totally nonexistent....except when I'm using the Camera or Selecting an Image from the Camera roll.

If the user chooses the camera vs. the roll....the camera works fine...takes a picture and then when they select "Use" it crashes. Same thing for the camera roll. I'm a noob so if I messed something up it wouldn't surprise me. Any help/suggestions greatly appreciated...here's the code:

    -(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhoto) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];
    //[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [picker release];
}
A: 

The only issue that jumps out at me is that UIImagePickerControllerOriginalImage is an NSString constant, so you don't want to put it in quotes:

theimageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

But even if that line were to fail, it would only set theimageView.image to nil which probably shouldn't cause a crash. You should see at least some more info about the crash in the Xcode Console, which will help. Also, check out the tips in this SO answer.

Daniel Dickison
Thanks for the link. I think there's a multitude of things happening here and making it all nice and neat will help it run better.
Indy-Jones
A: 

Your problem might be, since you use the original image, since its something like 1400x750 (not sure about the exact dimensions), you are probably running out of memory when you are setting it as the image of the imageview to be displayed...You should probably resize your image to 320x480 or 480x320 to display it in the image view, that will probably fix your problem.

Daniel
This was a great suggestion. I took your comment and combined it with another from another site and reduced the image size, and also created a UIImage in my class...set the resized photo to that, and then set the UIImageView.image property to the UIImage. All of that seems to make the app work much better.
Indy-Jones