gpt4 book ai didi

ios4 - 正确发布UIImagePickerController

转载 作者:行者123 更新时间:2023-12-02 08:54:09 25 4
gpt4 key购买 nike

我对此有点困惑,因为我见过太多不同的变体,并且不确定哪一个是正确的方法。目前我有:

- (IBAction)pickImageFromLibrary:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentModalViewController:picker animated:YES];

// [picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0f, 10.0f, 320.0f, 264.0f)];

self.studyView = imageView;

[imageView release];

[self.tableView setTableHeaderView:studyView];

self.fitImage = [ImageHelper image:image fitInView:studyView];

if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

studyView.image = self.fitImage;

[self dismissModalViewControllerAnimated:YES];

[picker release];
}

我在第一个方法中分配了UIImagePickerController,但是当我关闭它时仅在第二个方法中释放它不是合乎逻辑的吗?

最佳答案

不,因为它在通过 presentModelViewController 以模态方式呈现时被保留。这是在呈现新 View Controller 时会发现的常见模式,无论是否是模态视图 Controller 、自定义 View Controller 。这很好:

- (IBAction)pickImageFromLibrary:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentModalViewController:picker animated:YES];

[picker release];
}

关于ios4 - 正确发布UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6251072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com