0

我已从文档目录中检索图像并希望在滚动视图中显示该图像。图像来自文档目录,但未显示在滚动视图中。我有下面的代码。我已经将滚动视图放在 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);
}
4

1 回答 1

0

似乎您正在尝试从位于您的资源中的图像创建 UIImageView (但它们不存在!)。

[imageView setImage: [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]]];

如果您不使用它,将图像放入数组有什么意义?

试试这个:

[imageView setImage: [images objectAtIndex:i]];
于 2013-07-20T13:06:27.697 回答