Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iphone中使用imagepickercontroller的最佳方法?_Iphone_Ios_Ipad - Fatal编程技术网

在iphone中使用imagepickercontroller的最佳方法?

在iphone中使用imagepickercontroller的最佳方法?,iphone,ios,ipad,Iphone,Ios,Ipad,我正在使用UIImagePickerController从应用程序中的照片库中选择图像。为此,我使用了两种不同的方法。首先,我使用了一个类varioubleUIImagePicker,下面是代码 imagepicker = [[UIImagePickerController alloc]init]; imagepicker.delegate = self; imagepicker.sourceType = UIImagePickerControllerSourceT

我正在使用
UIImagePickerController
从应用程序中的照片库中选择图像。为此,我使用了两种不同的方法。首先,我使用了一个类variouble
UIImagePicker
,下面是代码

     imagepicker = [[UIImagePickerController alloc]init];
     imagepicker.delegate = self;
     imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
     imagepicker.modalTransitionStyle = UIModalTransitionStylePartialCurl;
     [self presentModalViewController:self.imagepicker animated:YES];
上面的代码工作正常。但当我点击按钮时,需要一些时间才能对本例中的动画做出反应。然后我使用了自动释放池方法

    NSAutoreleasePool *pool;
    pool = [[NSAutoreleasePool alloc] init]; 
    if([UIImagePickerController isSourceTypeAvailable:
        UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker= [[[UIImagePickerController alloc]init]autorelease];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.modalTransitionStyle = UIModalTransitionStylePartialCurl;
        [self presentModalViewController:picker animated:YES];

    }
    [pool release];

也很有魅力。两个都显示分析仪没有泄漏。有人能告诉我正确的方法吗。

好吧,这里没什么好说的。。。两种方法都有效,两种方法都是正确的,请使用您喜欢的方法


一个小要点:如果您定期演示图像选择器,最好使用第一种方法,并仅在第一次将其分配给实例变量(它不称为“类变量”!),并且在
-dealoc
之前不要释放它,每次用户选择图像时,您都会保存图像选择器的连续分配-取消分配。

@angry\u developer无所谓。“两者都能正确地管理内存。但是当我点击按钮时,它需要一些时间才能转到选择器?”愤怒的开发者显然是这样。那么现在呢?@angry_developer And
H2CO3
最好的方法之一就是将
imagePickerController
创建为
Singleton
。我认为是这样,但对于same@Kamarshad感谢您的支持,但是:对于视图控制器来说,单例并不是最好的模式。见我答案第二部分的建议:)