1

サーバーから呼び出す必要のある画像の配列を取得し、それを順番に並べる必要がありますが、以下のコードを実行している間は取得できません...ガイダンスをお願いします...

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

NSURL *url = [NSArray arrayWithObjects:[NSURL URLWithString: 
                                        @"http://images.wikia.com/marvelmovies/images/5/5e/The-hulk-2003.jpg"],
              [NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],
              [NSURL URLWithString:@"http://challenge.roadef.org/2012/img/google_logo.jpg"],
              [NSURL URLWithString:@"http://addyosmani.com/blog/wp-content/uploads/2012/03/Google-doodle-of-Richard-007.jpg"],
              [NSURL URLWithString:@"http://techcitement.com/admin/wp-content/uploads/2012/06/apple-vs-google_2.jpg"],
              [NSURL URLWithString:@"http://www.andymangels.com/images/IronMan_9_wallpaper.jpg"],
              [NSURL URLWithString:@"http://sequelnews.com/wp-content/uploads/2011/11/iphone_5.jpg"],Nil];

/*
int i=0;
int cord_x=0;
int cord_y=30;
int cont=0;

for (i = 0; i < [(NSArray*)url count]; i++) {
    cont=cont+1;
    if (cont > 3) {
        cord_x=0;
        cord_y=cord_y+110;
        cont=1;
    }*/

    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:(NSURL*)[(NSArray*)url objectAtIndex:index]]]; 

    //cord_x=cord_x+110;



UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200.0f, 200.0f);

[button setImage:(UIImage*)[image objectAtIndex:index] forState:UIControlStateNormal]; 

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return button;

}

//}

今、私はボタンの画像とサーバーからの画像を配置する必要があります...

4

4 に答える 4

2

NSURLConnection を使用して画像を非同期でダウンロードすると、UI の応答性が大幅に向上します。画像ごとに個別の接続をセットアップし、デリゲート メソッドのボタンの画像を更新するだけです - connectionDidFinishLoading. また、ダウンロード エラー (タイムアウトなど) を追跡するのにも役立ちます。これは、テーブルのダウンロード画像を使用した優れた例です。あなたのケースに関する多くのヘルプが見つかります: http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

于 2012-06-29T20:36:53.447 に答える
1
NSURL *url = [NSArray arrayWithObjects:[NSURL URLWithString:@"http://mobiledevelopertips.com/images/logo-iphone-dev-tips.png"],[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],Nil];


int i=0;
int cord_x=0;
int cord_y=30;
int cont=0;

for (i = 0; i < [(NSArray*)url count]; i++)
{
    cont=cont+1;
    if (cont > 3)
    {
        cord_x=0;
        cord_y=cord_y+110;
        cont=1;
    }

    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:(NSURL*)[(NSArray*)url objectAtIndex:i]]]; 
   UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cord_x, cord_y, 100, 100)];
    [imageView setImage:image];
    [self.view addSubview:imageView];
    cord_x=cord_x+110;
}
于 2012-06-27T06:58:46.887 に答える
1
 int row = 0;
int column = 0;

    for(int i = 0; i < url.count; ++i) {
    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:(NSURL*)   [(NSArray*)url objectAtIndex:i]]]; 

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(column*100+16, row*90, 80, 80);
    [button setImage:image forState:UIControlStateNormal]; 

    [button addTarget:self 
               action:@selector(buttonClicked:) 
     forControlEvents:UIControlEventTouchUpInside];
    button.tag = i; 
    [self.view addSubview:button];

    if (column == 2) {
        column = 0;
        row++;
    } else {
        column++;
    }
}
于 2012-06-27T07:00:09.323 に答える
1
NSMutableArray *arrayList=[[NSMutableArray alloc] initWithObjects:@"www.xxx.com/imag.jpg",@"www.xxx.com/img1.jpg",nil];
for(int i=0; i<[arrayList count]; i++)
{
    NSURL *url = [NSURL URLWithString:[arrayList ObjetAtIndex:i]];
    NSData *data = [NSData dataWithContentsOfURL: url];
    UIImage *img=[UIImage imageWithData:data];               // Here is your image
}
于 2012-06-27T06:55:56.563 に答える