iPhone:未调用 UIImagePickerControllerDelegate 方法? [英] iPhone: UIImagePickerControllerDelegate methods not Invoked?

查看:45
本文介绍了iPhone:未调用 UIImagePickerControllerDelegate 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 UIImagePickerController 的相机控制器:

@interface CameraController : UIImagePickerController//{}@结尾

Init 生成一个警告,指出 UINavigationControllerDelegate 未实现(这是预期的,因为我不希望我的对象成为该委托):

- (id) init{if(!(self = [超级初始化]))返回零;super.sourceType = UIImagePickerControllerSourceTypeCamera;//评论 delegat 没有帮助super.delegate = self;回归自我;}

尽管是 UIImagePickerControllerDelegate 委托,imagePickerController:didFinishPickingMediaWithInfo: 没有被调用.我还验证了其他两个委托方法也没有被调用.

如果我声称遵守 UINavigationControllerDelegateimagePickerController:didFinishPickingMediaWith 被调用,但我在 dismissModalViewControllerAnimated 上崩溃:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{断言有效(选择器);断言有效(信息);//评论没有帮助[选择器自动释放];UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];断言有效(图像);//图像处理注释掉//super.delegate = nil;//picker.delegate = nil;//[自我解雇ModalViewControllerAnimated:YES];//[超级解雇ModalViewControllerAnimated:YES];//[self performSelector:@selector(dismissModalViewControllerAnimated:) withObject:nil afterDelay:0.0f];//[自我解雇ModalViewControllerAnimated:NO];//[超级解雇ModalViewControllerAnimated:NO];[self performSelector:@selector(dismissModalViewControllerAnimated:) withObject:nil afterDelay:0.5f];}

我查看了有关此 CURSED 视图控制器的许多帖子.最接近的,UIImagePickerControllerDelegate 没有正确响应iPhone - UIImagePickerControllerDelegate 继承,没有帮助.

知道这次会是什么吗?立即想到两个问题:(1) 作为 UINavigationControllerDelegate 与调用我的图像回调有什么关系,以及 (2) 为什么这个对象不能正确清理自己?>

提前致谢,

解决方案

UIImagePickerController 类不应该是子类.参考手册说:

<块引用>

该类旨在用于原样且不支持子类化.

而且没有理由这样做.只需创建 UIViewController 的子类并实现委托.

我已经成功地使用了很多次.我一直声明我的视图控制器实现了 UINavigationControllerDelegate 但没有实现这个协议的任何方法.

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,

解决方案

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.

这篇关于iPhone:未调用 UIImagePickerControllerDelegate 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆