iphone - 在 iPhone 上加载超过 10 张图像?

标签 iphone image uiscrollview

我正在尝试在 ScrollView 上添加超过 10 张图片。

NSUInteger i;
for (i = 1; i <= numberOfImage; i++)
{
    NSString *imageName = [NSString stringWithFormat:@"d%dimage%d.png", imageSection, i];               

    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
    CGRect rect = imageView.frame;
    rect.size.height = kScrollObjHeight;
    rect.size.width = kScrollObjWidth;
    imageView.frame = rect;
    imageView.tag = i;  // tag our images for later use when we place them in serial fashion
    [scrollView addSubview:imageView];
    [imageView release];
}

此代码来自 Apple 示例,运行良好。但如果变量“i”大于 10,则“UIImage *image”为空。 imageName 似乎是正确的。但我不知道为什么它无法加载图像。有人看出问题了吗?

还有一件事。如果我这样做,iOS 会自动控制内存吗?我的意思是,如果所有(超过 10 个)图像都加载到内存中,即使它们没有显示,也会浪费内存。我听说 iOS 加载仅显示在屏幕上的图像以及免费未显示的图像。是对的吗?

感谢您的阅读。

最佳答案

UIimage imageNamed:缓存文件内容。我建议您使用 UIImage +imageWithContentsOfFile: 在这种情况下根本不缓存。

关于iphone - 在 iPhone 上加载超过 10 张图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5131813/

相关文章:

c# - 将图片显示为隐藏或可见

ios - 如何使用 UIScrollView 实现 UIPageViewController?

ios - 如何在 iOS 上的 UIScrollView 中正确替换 UIImageView 中的图像

iphone - 通过 IAP 每月订阅

当我构建并运行应用程序时,iPhone 模拟器屏幕是黑色的

java - 等待并通知 Objective c 中的等价物?

iphone - 使用 UIScrollView 在多个图像之间水平滚动

iphone - 检查是否设置了 BOOL(不能用 ==nil 完成)

php - 使用 jquery/php/html 更改 img src 和 fileupload 值

css - 动态图像调整大小