views:

92

answers:

1

Hello All,

I have a problem that I'm helping someone can shed some light on. I'm sure it is something very simple, but I just can't see it and could really use an extra set of eyes to help find this bug.

The app I'm working on uses UIImagePickerController to present a camera preview with the stock camera UI hidden. This preview implements a cameraOverlay view with a few buttons to perform my required tasks, one of which is to dismiss the camera preview.

For some reason, the function to dismiss the camera view will not work when being called by the button in the overlay view. I can NSLog the function and see that it is in fact being called by the button, but simply doesn't allow the dismissModalViewController to work. I have tested the function by having an NSTimer call it a few seconds after it loads, and it works fine, just not when I call it from the button in the cameraOverlay.

My viewController (CameraTestViewController.m) calls the UIImagePicker as shown below with the press of a button.

-(IBAction) getPhoto:(id) sender {


    OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
    picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    picker.cameraOverlayView = overlay;
    picker.showsCameraControls = NO;
    picker.toolbarHidden = YES;
    [self presentModalViewController:picker animated:NO];
    //[self performSelector:@selector(doCancel) withObject:nil afterDelay:10];

}

I dismiss the camera view with this method elsewhere in the viewController

-(void)doCancel
{   
    NSLog (@"doCancel method has been called");
    [picker dismissModalViewControllerAnimated:YES];
}

Then in my OverlayView.m class, I set up the required buttons and provide a method that calls the dismissing of the modal view controller.

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Clear the background of the overlay:
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

                  ...

myButton04 = [UIButton buttonWithType:UIButtonTypeCustom];
        myButton04.frame = CGRectMake(10, 447, 44, 13);
        [myButton04 setTitle:@"" forState:UIControlStateNormal];
        [myButton04 addTarget:self action:@selector(scanButton05TouchUpInside) forControlEvents:UIControlEventTouchUpInside];
        [myButton04 setImage:[UIImage imageNamed:@"camControlsBack.png"] forState:UIControlStateNormal];
        [self addSubview:myButton04];

                  ...

    }

    return self;

}


- (void) scanButton05TouchUpInside {

    NSLog(@"BACK BUTTON HAS BEEN PRESSED");
    CameraTestViewController *baseViewController = [[CameraTestViewController alloc] init];
    [baseViewController doCancel];

}

ANY help on this would be most appreciated. I'm sick of having a purple forehead from beating my head against the wall over this one. :cool:

THANKS!

A: 

The way I dismiss my modalViewController is to call its parent:

[[picker parentViewController] dismissModalViewControllerAnimated:YES];
OlivaresF
I've tried this as well, and no luck. The problem doesn't seem to be the dismissModalViewController task inside the 'doCancel' method. I can make that code work when I call it programmatically for testing. The camera view dismisses as it should under those conditions, but not when I call the exact same function from the button contained inside the OverlayView of the camera. ?!?!
viewPusher
Is it possible that something is stuck in memory and preventing that view from dismissing? I can't think why a function that is obviously being called would work under one set of conditions, but not another.
viewPusher