【发布时间】:2011-02-27 06:33:31
【问题描述】:
我正在尝试在 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 会加载仅显示在屏幕上的图像和未显示的免费图像。是对的吗?
感谢阅读。
【问题讨论】:
-
尝试静态设置框架,看看屏幕上是否出现图像
标签: iphone image uiscrollview