Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Objective c 将图像数加载到UIScrollView时由于内存错误而终止_Objective C_Memory Management_Ios7_Uiscrollview_Reusability - Fatal编程技术网

Objective c 将图像数加载到UIScrollView时由于内存错误而终止

Objective c 将图像数加载到UIScrollView时由于内存错误而终止,objective-c,memory-management,ios7,uiscrollview,reusability,Objective C,Memory Management,Ios7,Uiscrollview,Reusability,我在我的应用程序中使用UIScrollView,加载了大量图像(超过200张图像) 我从磁盘加载图像,只需将其添加到UIScrollView。我收到Xcode 5错误消息“由于内存错误而终止”,并且应用程序意外终止。但并非每次都偶尔发生这种情况 我仍然不能确定这是否是内存问题,但我没有找到导致内存问题的代码 即使我已经通过仪器工具检查了内存泄漏问题,也没有内存泄漏 由于创建对象的效率和时间,我已经在customAcreUserue的帮助下为UIScrollView创建了自定义的可重用UIView

我在我的应用程序中使用
UIScrollView
,加载了大量图像(超过200张图像)

我从磁盘加载图像,只需将其添加到
UIScrollView
。我收到Xcode 5错误消息“由于内存错误而终止”,并且应用程序意外终止。但并非每次都偶尔发生这种情况

我仍然不能确定这是否是内存问题,但我没有找到导致内存问题的代码

即使我已经通过仪器工具检查了内存泄漏问题,也没有内存泄漏

由于创建对象的效率和时间,我已经在custom
AcreUserue
的帮助下为
UIScrollView
创建了自定义的可重用
UIView
类,类似于
UITableView

我在
scrollViewDidScroll
中实现了排队和退队的概念:

将图像添加到
UIScrollView
:用于以下代码

-(void)imageAdd:(ALAsset *)item
{
__block ImageControl    *imageControl;
imageControl = (ImageControl*)[[ACReuseQueue defaultQueue]       dequeueReusableObjectWithIdentifier:@"ImageControl"];
    [imageControl setAlAsset:item];
    [imageControl setDuration:1.0];
    [imageControl setIsCopy:NO];

    [self.galleryView addItem:imageControl];
    [imageControl release];
}
下面的代码用于在用户滚动滚动滚动视图时

-(void)scrollViewDidScroll:(UIScrollView*)scrollView
{
for (ImageControl *imageControl in self.galleryView.items)
{

    if (CGRectIntersectsRect(imageControl.frame, self.galleryView.bounds))
    {
        imageControl = (ImageControl*)[[ACReuseQueue defaultQueue] dequeueReusableObjectWithIdentifier:@"ImageControl"];


        [self.galleryView addItem:imageControl];


    }
    else
    {
        [imageControl removeFromSuperview];
        [[ACReuseQueue defaultQueue] enqueueReusableObject:imageControl];

    }
}
}

尽管如此,我还是没有实现可重用的
UIScrollView
,比如
UITableView
不要同时加载所有图像。大多数都是看不见的

使用表视图可能会使您的生活更加轻松,并且是只加载所需图像的最快方式


如果要使用纯滚动视图,则需要实现
scrollViewDidScroll:
delegate方法,并使用它在用户滚动视图时添加和删除子视图。

图像太大。如果你不断添加它们,而且它们很大,它们就不需要泄漏。你需要使用一个单元策略或者其他方法,从内存中删除屏幕上不再显示的图像。