-1

I have a camera controller based on a UIImagePickerController:

@interface CameraController : UIImagePickerController
    <UIImagePickerControllerDelegate>
    // <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
}

@end

Init generates a warning that UINavigationControllerDelegate is not implemented (it is expected since I don't want my object to be that delegate):

- (id) init
{
    if(!(self = [super init]))
        return nil;

    super.sourceType =  UIImagePickerControllerSourceTypeCamera;
    // Commenting delegat does not help
    super.delegate = self;

    return self;
}

Despite being a UIImagePickerControllerDelegate delegate, imagePickerController:didFinishPickingMediaWithInfo: is not called. I also verified the other two delegate methods are not being called either.

If I do claim adherence to UINavigationControllerDelegate, imagePickerController:didFinishPickingMediaWith is called but I crash on dismissModalViewControllerAnimated:

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

    // Commenting does not help
    [picker autorelease];

    UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];   
    ASSERT_VALID(image);

    // Image processing commented out

    // super.delegate = nil;
    // picker.delegate = nil;

    // [self dismissModalViewControllerAnimated:YES];
    // [super dismissModalViewControllerAnimated:YES];
    // [self performSelector:@selector(dismissModalViewControllerAnimated:) withObject:nil afterDelay:0.0f];
    // [self dismissModalViewControllerAnimated:NO];
    // [super dismissModalViewControllerAnimated:NO];
    [self performSelector:@selector(dismissModalViewControllerAnimated:) withObject:nil afterDelay:0.5f];
}

I've looked at a number of posts on this CURSED view controller. The closest, UIImagePickerControllerDelegate not responding properly and iPhone - UIImagePickerControllerDelegate inheritance, did not help.

Any ideas what might be this time? Two questions immediately come to mind: (1) what does being a UINavigationControllerDelegate have to do with invoking my callback with the image, and (2) why can't this object clean itself up properly?

Thanks in advance,

jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

1

The UIImagePickerController class is not supposed to be subclassed. The reference manual says:

This class is intended to be used as-is and does not support subclassing.

And there's no reason to. Just create a subclass of a UIViewController and implement the delegates.

I've successfully used it many times. I've always declared that my view controller implements UINavigationControllerDelegate but haven't implemented any of the methods of this protocol.

Codo
  • 75,595
  • 17
  • 168
  • 206
  • Thanks Codo. Its frustrating that I run with full warnings (`-Wall -Wextra`) and Clang and did not get one complaint. I would have expected the static analyzer to produced an item. In general, I really miss the advanced analyzer in Visual Studio (SAL). (Not sure if it would have caught a similar issue, though). – jww Apr 04 '11 at 11:11
  • `The UIImagePickerController class supports portrait mode only.` Its funny how Apple hides the subclassing issue behind a discussion of portrait/lanscape modes. I stopped reading that paragraph immediately because I only support portrait mode. Assholes. – jww Apr 04 '11 at 11:15