我已经从文档目录中恢复了图像,并希望在scrollview中显示这些图像。图像来自文档目录,但不显示在scrollview中。我有以下代码。我已经将scrollview放在xib上,并且还创建了插座..
self.scrollView.contentSize = CGSizeMake(320, 136);
self.scrollView.delegate = self;
int X=0;
for (int i = 0; i < [imageFileNames count]; i++)
{
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d/%d.png",b, i]];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
[images addObject:img];
NSLog(@"%@",getImagePath);
//imge.image=img;
UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(X, 0, 100, 100)] ;
[imageView setImage: [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]]];
[self.scrollView addSubview: imageView];
X = X + imageView.frame.size.height+5;
if(X > 320)
self.scrollView.contentSize = CGSizeMake(X, 140);
}
答案 0 :(得分:0)
似乎你试图从资源中的图像创建UIImageView(但它们不存在!)。
[imageView setImage: [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]]];
如果你不使用它,那么将图像放在一个数组中是什么意思?
试试这个:
[imageView setImage: [images objectAtIndex:i]];