Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...