开发者

UIImagePickerController Problem

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 presentModalViewC开发者_开发知识库ontroller: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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜