加载滚动视图会导致"其他进程"内存上升并导致应用程序崩溃

时间:2014-09-20 01:56:52

标签: ios memory-leaks uiimage scrollview

我的程序正在将文档文件中的图像加载到滚动视图中的按钮中,并且每次程序执行此操作时都会导致内存使用率大约超过1mb,这不是什么大不了的事。让我的应用程序崩溃的原因是“其他进程”每次也会跳跃20-30mb。有人可以帮我解决这个问题吗?非常感谢。

以下是加载数组中图像字符串名称的代码:

- (void) saveUserFilesToArray;
{

    NSString *slidePath = [globe.pathToSave stringByAppendingPathComponent:@"/UserSlides"];
    NSString *iconPath = [globe.pathToSave stringByAppendingPathComponent:@"/UserIcons"];

    NSArray *iconContents = [globe.fileSystem contentsOfDirectoryAtPath:iconPath error:nil];
    NSArray *slideContents = [globe.fileSystem contentsOfDirectoryAtPath:slidePath error:nil];

    customIcon = iconContents;
    customSlide = slideContents;

}

以下是将图像加载到滚动视图中的代码:

- (void) loadCustomScroll
{
    for (int i = 0; i < [customIcon count]; i++)
    {
        NSString* path = [globe.pathToSave stringByAppendingPathComponent: [NSString stringWithFormat:@"UserIcons/%@", customIcon[i]]];
        UIImage* imageToUse = [UIImage imageWithContentsOfFile:path];

        UIView *overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menuSingle"]];
        UIButton *icon1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [icon1 setBackgroundImage:imageToUse forState:UIControlStateNormal];

        icon1.showsTouchWhenHighlighted = YES;
        icon1.titleLabel.text = customSlide[i];
        icon1.titleLabel.hidden = YES;

        [icon1 addTarget:self action:@selector(getName:) forControlEvents:UIControlEventTouchUpInside];

        CGRect scrollFrame;
        scrollFrame.origin = customSlideView.frame.origin;
        scrollFrame.size = CGSizeMake(200, 200 * i + 200);
        customSlideView.frame = scrollFrame;

        CGRect overlayFrame = overlay.frame;
        CGRect icon1Frame = icon1.frame;

        overlayFrame.size.width = 200;
        overlayFrame.size.height = 200;
        [overlay setFrame:overlayFrame];

        icon1Frame.size.width = 200;
        icon1Frame.size.height = 200;
        [icon1 setFrame:icon1Frame];

        [customSlideView addSubview: icon1];
        [customSlideView addSubview: overlay];

        CGPoint pt = CGPointMake((overlay.frame.size.width/2) + 65, (overlay.frame.size.height/2) + (overlay.frame.size.height * i));

        CGPoint iconLeft = CGPointMake((overlay.frame.size.width/2) + 65, (overlay.frame.size.height/2) + (overlay.frame.size.height * i));


        overlay.center = pt;

        icon1.center = iconLeft;

        customSlideView.contentSize = CGSizeMake(200, 200 * i + 200);

    }
}

- (void)getName:(UIButton *)sender
{
    globe.selectedPic = sender.titleLabel.text;

    [self performSegueWithIdentifier:@"customDisplay" sender:self];

}

0 个答案:

没有答案