Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

ios - iPhone: UIImagePickerControllerDelegate methods not Invoked?

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...