2011-07-01 19 views
0
enter code hereint quantity = [array count]; 
int i; 
for (i=0; i<quantity; i++) 
{ 
    NSString *imageName = [NSString stringWithFormat:@"Car_%@.jpg", [[array objectAtIndex:i] objectForKey:@"CarName"]] ]; 
    UIImage *img[i] = [UIImage imageNamed:imageName]; 
    UIImageView *imgView[i] = [[UIImageView alloc] initWithImage:img[i]]; 
    imgView[i].frame = CGRectMake(i*kWidth, 0, kWidth, kHeight); 
    [scrollView addSubview:imgView[i]]; 
    [imgView[i] release]; 
}`enter code here` 

エラー:可変サイズのオブジェクトは初期化できません。しかし、なぜ?エラー:可変サイズのオブジェクトが初期化されていない可能性があります。しかし、なぜ?

答えて

1

あなたはこれを試してみたいことがあります。

int i; 
for (i=0; i<quantity; i++) 
{ 
    NSString *imageName = [NSString stringWithFormat:@"Car_%@.jpg", [[array objectAtIndex:i] objectForKey:@"CarName"]] ]; 
    UIImage *img = [UIImage imageNamed:imageName]; 
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; 
    imgView.frame = CGRectMake(i*kWidth, 0, kWidth, kHeight); 
    [scrollView addSubview:imgView]; 
    [imgView release]; 
} 

あなたはIMGを使用する必要はありません[i]はUIImageViewとscrollviewを移入するために。

2
UIImage *img[i] = [UIImage imageNamed:imageName]; 

これはサイズiUIImageのインスタンスでそれを初期化する試みのCスタイルの配列を宣言する。それは意味をなさない。あなたは何をしようとしているのですか?残りのコードはどこにありますか?

編集:

さて、私はあなたがやっているかを見ると思います。あなたは[i]を持っているすべての場所を取り除くだけです。ループ内では、一度に1つのアイテムしか扱わず、そうでない場合でも、配列をどのように使用するかは異なります。

関連する問題