【问题标题】:iPhone: UIImagePickerControllerDelegate methods not Invoked?iPhone:未调用 UIImagePickerControllerDelegate 方法?
【发布时间】:2011-07-28 23:52:21
【问题描述】:

我有一个基于 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: 没有被调用。我还验证了其他两个委托方法也没有被调用。

如果我确实声称遵守 UINavigationControllerDelegateimagePickerController: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)为什么这个对象不能正确清理自己?

提前致谢,

【问题讨论】:

    标签: iphone ios uiimagepickercontroller


    【解决方案1】:

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

    该类旨在用于 按原样,不支持 子类化。

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

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

    【讨论】:

    • 谢谢科多。令人沮丧的是,我带着完整的警告 (-Wall -Wextra) 和 Clang 运行并且没有收到任何投诉。我原以为静态分析器会生成一个项目。总的来说,我真的很怀念 Visual Studio (SAL) 中的高级分析器。 (但不确定它是否会遇到类似的问题)。
    • The UIImagePickerController class supports portrait mode only. 有趣的是,Apple 如何在讨论纵向/横向模式的背后隐藏子类化问题。我立即停止阅读该段落,因为我只支持纵向模式。混蛋。
    猜你喜欢
    • 1970-01-01
    • 2018-09-01
    • 2016-01-21
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2021-01-27
    相关资源
    最近更新 更多