Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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
Ios ImagePickerController使我的应用程序崩溃,并说;收到内存警告“;当我的设备上运行其他应用程序时(2个或更多应用程序)_Ios_Objective C_Automatic Ref Counting_Low Memory - Fatal编程技术网

Ios ImagePickerController使我的应用程序崩溃,并说;收到内存警告“;当我的设备上运行其他应用程序时(2个或更多应用程序)

Ios ImagePickerController使我的应用程序崩溃,并说;收到内存警告“;当我的设备上运行其他应用程序时(2个或更多应用程序),ios,objective-c,automatic-ref-counting,low-memory,Ios,Objective C,Automatic Ref Counting,Low Memory,当我从照相机(UIImagePickerController)拍照时,我的应用程序崩溃,并说“收到内存警告” 发生崩溃时的场景:如果我的设备上运行了其他应用程序(2个或更多),我将发生崩溃,如果在我启动应用程序之前只有一个其他应用程序在运行或没有其他应用程序在运行,则根本不会发生崩溃 只有当我从相机中拍摄照片时才会发生崩溃,但当我从照片库中选择照片时,根本没有崩溃 我使用的是Xcode 4.3.2,我使用的是ARC 有人能帮我吗 这是我正在使用的代码 -(void)actionSheet:(UI

当我从照相机(
UIImagePickerController
)拍照时,我的应用程序崩溃,并说“
收到内存警告”

发生崩溃时的场景:如果我的设备上运行了其他应用程序(2个或更多),我将发生崩溃,如果在我启动应用程序之前只有一个其他应用程序在运行或没有其他应用程序在运行,则根本不会发生崩溃

只有当我从相机中拍摄照片时才会发生崩溃,但当我从照片库中选择照片时,根本没有崩溃

我使用的是Xcode 4.3.2,我使用的是ARC

有人能帮我吗

这是我正在使用的代码

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex: (NSInteger)buttonIndex 
{

    if (buttonIndex < 2) 
    {
        if([UIImagePickerController isSourceTypeAvailable:buttonIndex==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
            [ipc setDelegate:(id<UIImagePickerControllerDelegate,UINavigationControllerDelegate>) self];
            [ipc setSourceType:buttonIndex==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary];
            if (buttonIndex == 0) 
            {
                [ipc setAllowsEditing:NO];
            }
            [ipc setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]];
            [self presentModalViewController:ipc animated:YES];
        }
        else 
        {
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Action Alert" message:@"Camera is not available in this device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }
    }
}



    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {

        [self dismissModalViewControllerAnimated:YES];
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        if (!image) image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [NSThread detachNewThreadSelector:@selector(scallImage:) toTarget:self withObject:image];
}




 -(void) scallImage:(UIImage *) image
    {
    CGSize newSize = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    image=nil;
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSString *cImage = [UIImageJPEGRepresentation(newImage, 0.5) base64EncodedString];
    [ImageButton setBackgroundImage:newImage forState:UIControlStateNormal];
    [ImageButton setHidden:NO];
    //[profileImageButton setBackgroundImage:newImage forState:UIControlStateNormal];
    newImage=nil;
}
-(void)操作表:(UIActionSheet*)操作表使用buttonIndex:(NSInteger)buttonIndex进行解除
{
如果(按钮索引<2)
{
如果([UIImagePickerController isSourceTypeAvailable:buttonIndex==0?UIImagePickerController源TypeCamera:UIImagePickerController源TypePhotoLibrary])
{
UIImagePickerController*ipc=[[UIImagePickerController alloc]init];
[ipc setDelegate:(id)self];
[ipc设置资源类型:按钮索引==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary];
如果(按钮索引==0)
{
[ipc设置允许编辑:否];
}
[ipc setMediaTypes:[NSArray arrayWithObjects:(NSString*)kUTTypeImage,无]];
[自我呈现模式控制器:ipc动画:是];
}
其他的
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“操作警报”消息:@“相机在此设备中不可用”。代理:nil cancelButtonTitle:@“确定”其他按钮:nil];
[警报显示];
}
}
}
-(void)imagePickerController:(UIImagePickerController*)picker未使用信息完成PickingMediaWithInfo:(NSDictionary*)信息
{
[自我解散Modalviewcontrolleranimated:是];
UIImage*image=[info objectForKey:UIImagePickerControllerEditedImage];
如果(!image)image=[info objectForKey:UIImagePickerControllerOriginalImage];
[NSThread detachNewThreadSelector:@selector(ScalImage:)toTarget:self with Object:image];
}
-(空)缩放图像:(UIImage*)图像
{
CGSize newSize=CGSizeMake(320480);
UIGraphicsBeginImageContext(新闻大小);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
图像=零;
UIImage*newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
NSString*cImage=[UIImageJPEGRepresentation(newImage,0.5)base64EncodedString];
[ImageButton setBackgroundImage:newImage for状态:UIControlStateNormal];
[图像按钮设置隐藏:否];
//[profileImageButton setBackgroundImage:newImage for状态:UIControlStateNormal];
newImage=nil;
}

我的代码中有什么错误吗?

尝试避免使用该方法分配UIImagePickerController。而是在viewDidLoad中分配它。将这行代码放入viewDidLoad:

 ipc = [[UIImagePickerController alloc] init];
并在.h文件中首先声明它


希望这能有所帮助。

我终于意识到,通过从项目中删除一些不需要的图像/资源,我可以运行我的应用程序而不会崩溃。。。!!!谢谢所有帮助我的人

这种情况是在第一张图片显示后发生的,还是有许多UIImage对象被加载、驻留和显示(例如,像在表视图中)?这种情况以任何一种方式发生,在方法的末尾显示“ipc”都会被释放,因为我在ARC上,它会在viewDidUnload后被释放。因此,如果我执行“ipc=nil”在我的工作完成后,它会释放吗?因为我正在删除引用!