Search code examples
iphonecamerauiimagepickercontrollerviewdidappear

UIImagepickerController [takepicture] modal view disappears no delegate callback


Update:

This has been answered. It was my own stupidity, possibly not worth reading any more of this question. lol.

Question:

Right so i have this UIViewController(master) subclass, it has a UIImagepickerController(camera), it also has a UIView(overlayView). Master setups the camera to be configured as a camera only with a custom cameraOverlay, hiding the custom controls e.t.c.

All appears to work fine apart from when i try to programatically take a picture. What happens is the overlayView calls the master and this triggers the take picture, then i hear the shutter sound and the iris closes, the camera appears to dismiss itself (i am defiantly not doing this in my code) and then my viewDidAppear gets called in my master again.

Anybody have any idea whats going on ?

    -(void)viewDidLoad
{
    NSLog(@"loading the view");
    //if the camera is on the device
    if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    {
        //make one
        camera = [[UIImagePickerController alloc] init];
        //setup some settings that we need
        camera.sourceType = UIImagePickerControllerSourceTypeCamera;
        camera.showsCameraControls = NO;
        camera.navigationBarHidden = NO;
        camera.toolbarHidden = YES;
        camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform, 1.03, 1.03);
        //show it
        overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0,0,320,480) withDelegate:self andController:self];
        camera.cameraOverlayView = overlayView;
            camerashowing=NO;

    }
    else 
    {
        alert = [[UIAlertView alloc] initWithTitle:@"No Camera Detected" message:@"The camera is broken or your device has no camera. Please close the application" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
}

-(void)viewDidAppear:(BOOL)animated
{
  if (!cameraShowing)
  {
    NSLog(@"going to show camera");
    [self presentModalViewController:camera animated:NO];
    camerashowing = YES;
  }
}



 -(void)releaseShutter
  { 
    [overlayView toolbarShowWarning];
    NSLog(@"going to show camera: %@", self);
    [camera takePicture]; 

    }

After some help advice from people in the answers i can say that the camera is not being released.

I have also managed to stop the exec_bad_access by stopping it from calling [presentmodal....] for a second time by checking a bool value in the viewDidAppear Method.

I still have the issue where the modal view disapears, any help, again lol ??


Solution

  • I think you're missing a camera.delegate = self;