Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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 UIImageView带摄像头或摄像头滚轮选择器内存警告级别2_Iphone_Xcode_Uiimageview_Camera_Picker - Fatal编程技术网

iPhone UIImageView带摄像头或摄像头滚轮选择器内存警告级别2

iPhone UIImageView带摄像头或摄像头滚轮选择器内存警告级别2,iphone,xcode,uiimageview,camera,picker,Iphone,Xcode,Uiimageview,Camera,Picker,我很快就要完成我的第一个应用程序了。一切正常,几乎不存在内存泄漏……除非我使用相机或从相机卷中选择图像 如果用户选择相机而不是滚动…相机工作正常…拍摄一张照片,然后当他们选择“使用”时,它崩溃。镜头卷也是一样。我是个笨蛋,所以如果我把事情搞砸了,我也不会感到惊讶。非常感谢您的任何帮助/建议……以下是代码: -(IBAction) getPhoto:(id) sender { UIImagePickerController * picker = [[UIImagePickerCon

我很快就要完成我的第一个应用程序了。一切正常,几乎不存在内存泄漏……除非我使用相机或从相机卷中选择图像

如果用户选择相机而不是滚动…相机工作正常…拍摄一张照片,然后当他们选择“使用”时,它崩溃。镜头卷也是一样。我是个笨蛋,所以如果我把事情搞砸了,我也不会感到惊讶。非常感谢您的任何帮助/建议……以下是代码:

    -(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhoto) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];
    //[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [picker release];
}

我遇到的唯一问题是,
UIImagePickerControllerOriginalImage
是一个
NSString
常量,因此您不想将其括在引号中:

theimageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

但即使该行失败,它也只会将image view.image设置为nil,这可能不会导致崩溃。您应该在Xcode控制台中至少看到一些关于崩溃的更多信息,这将有所帮助。另外,请查看中的提示。

您的问题可能是,因为您使用的是原始图像,因为它类似于1400x750(不确定确切的尺寸),当您将图像设置为要显示的图像视图的图像时,可能内存不足……您可能应该将图像调整为320x480或480x320以在图像视图中显示,这可能会解决您的问题。

更改
[picker dismissModalViewControllerAnimated:是];

[自我解散Modalviewcontrolleranimated:是];

这应该行得通

谢谢你的链接。我认为这里发生了很多事情,让它变得漂亮整洁将有助于它更好地运行。这是一个很好的建议。我接受了你的评论,并将其与另一个站点的评论相结合,缩小了图像大小,还在我的类中创建了一个UIImage…将调整大小的照片设置为该值,然后将UIImageView.image属性设置为UIImage。所有这些似乎都让应用程序运行得更好。