UIImagePickerController问题

发布于 2024-10-08 19:10:05 字数 922 浏览 1 评论 0原文

我在 UIImagePickerController 中遇到了一个相当奇怪的错误。 (或者我做错了什么)

我这样加载控制器:

    UIImagePickerController*controller = [[UIImagePickerController alloc] init];

    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [controller setDelegate:self];

    [firstView presentModalViewController:controller animated:YES];

现在问题如下:代码运行良好,但只能运行一次。它作为一个操作与 UIButton 绑定在一起 - 如果我第二次单击它而不是 UIImagePickerController 我会看到一个半透明(alpha 0.8ish?)黑色视图出现,我不能驳回。

我在任何地方都没有创建这样的视图,只有该操作中的 UIImagePickerController 。

我在委托中驳回了它:

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {
        [firstView dismissModalViewControllerAnimated:YES];
        [picker release];
    }

这也能正常工作。

我做错了什么/这是一个错误吗?

I've come across a rather weird bug in UIImagePickerController. (or I'm doing something wrong)

I load the controller as such:

    UIImagePickerController*controller = [[UIImagePickerController alloc] init];

    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [controller setDelegate:self];

    [firstView presentModalViewController:controller animated:YES];

Now the problem is the following: The code works great, but only once. It's tied to an UIButton as an action - if I click it the second time instead of the UIImagePickerController I get a translucent (alpha 0.8ish?) black view appearing, which I can't dismiss.

I create no such view anywhere, it's only the UIImagePickerController that is in that action.

I dismiss it in the delegate:

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {
        [firstView dismissModalViewControllerAnimated:YES];
        [picker release];
    }

and this works as it should as well.

What am I doing wrong / is this a bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-10-15 19:10:05

我相信你想要做的是在呈现之后释放控制器:

UIImagePickerController*controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[controller setDelegate:self];
[firstView presentModalViewController:controller animated:YES];
// Here...
[controller release];

而不是在完成之后:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [firstView dismissModalViewControllerAnimated:YES];
    // Not here...
    //[picker release];
}

presentModalViewController将在持续时间内保留控制器并适当地释放它。

I believe what you want to do is release the controller after the present:

UIImagePickerController*controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[controller setDelegate:self];
[firstView presentModalViewController:controller animated:YES];
// Here...
[controller release];

And not in the did finish:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [firstView dismissModalViewControllerAnimated:YES];
    // Not here...
    //[picker release];
}

The presentModalViewController will retain the controller for the duration and release it appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文