iPhone:UIImagePickerControllerDelegate方法没有被调用?

时间:2011-04-04 07:48:49

标签: iphone ios uiimagepickercontroller

我有一个基于UIImagePickerController的摄像头控制器:

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

@end

Init生成警告UINavigationControllerDelegate未实现(由于我不希望我的对象成为该委托,因此预期会出现):

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

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

    return self;
}

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

如果我确实声称遵守UINavigationControllerDelegate,则imagePickerController:didFinishPickingMediaWith 调用,但我在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];
}

我看过这个CURSED视图控制器上的一些帖子。最接近的UIImagePickerControllerDelegate not responding properlyiPhone - UIImagePickerControllerDelegate inheritance没有帮助。

这次可能有什么想法?立即浮现两个问题:(1)UINavigationControllerDelegate与图像调用我的回调有什么关系,以及(2)为什么这个对象不能正确地清理自己?

提前致谢,

1 个答案:

答案 0 :(得分:1)

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

  

本课程旨在使用   原样,不支持   子类。

没有理由。只需创建UIViewController的子类并实现委托。

我已多次成功使用它。我一直声明我的视图控制器实现UINavigationControllerDelegate但没有实现此协议的任何方法。