[英]Scrollview not shwoing images
我已从文档目录中检索图像,并希望在滚动视图中显示该图像。 图像来自文档目录,但未显示在滚动视图中。 我有以下代码。 我已经将xibgraview放到了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);
}
似乎您正在尝试根据资源中的图像创建UIImageView(但它们不存在!)。
[imageView setImage: [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]]];
如果不使用图像,将图像放置在阵列中有什么意义?
试试这个代替:
[imageView setImage: [images objectAtIndex:i]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.