2

画像の URL を含む配列があります。これらの URL を使用して画像ビューを作成したいと考えています (現在は for ループを使用しています)。

しかし、私はアイデアを得ていません.配列内のURLを使用して画像ビューを作成する方法

int x = 0;
for(int i = 0; i <imagearry.count; i ++){
NSDictionary *dict = [imagearry objectAtIndex:i];
NSLog(@"%@",[dict objectForKey:@"img_url"]);
NSString *filePath [NSHomeDirectory()stringByAppendingPathComponent:@"/Library/Caches"];

    stringarry = [[imagearry objectAtIndex:i] objectForKey:@"img_url"];

    int x = 0;

    imageView.image = [UIImage imageNamed:[stringarry objectAtIndex:0]];

    for(int i=0; i < [stringarry count]; i++)
    {

        UIImageView *img = [[UIImageView alloc] init];
        img.bounds = CGRectMake(10, 10, 50, 50);
        img.frame = CGRectMake(5+x, 0, 160, 110);
        NSLog(@"image: %@",[stringarry objectAtIndex:i]);


        img.image = [UIImage imageNamed:[stringarry objectAtIndex:i]];
        [stringarry insertObject:img atIndex:i];
         [scrollView addSubview:[stringarry objectAtIndex:i]];

        x += 170;
4

2 に答える 2

0

UIImageView には、URL から画像を表示するプロパティがありません。したがって、NSDATA 形式でダウンロードしてから変換する UIImage必要がある場合があります。代わりに、AsyncImageView を見て、配列内に AsyncImageView のインスタンスを格納します。

このリンクを確認してください: AsyncImageView

于 2012-10-30T11:16:52.000 に答える
0

imageWithData代わりに使用する必要がありますimageNamed

NSURL * url = [NSURL fileURLWithPath:[filePath stringByAppendingPathComponent:[stringarry objectAtIndex:i]]];
[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
于 2012-10-30T11:13:12.880 に答える