Error: Variable-sized object may not be initialized. But why?
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开发者_JS百科[i].frame = CGRectMake(i*kWidth, 0, kWidth, kHeight);
[scrollView addSubview:imgView[i]];
[imgView[i] release];
}`enter code here`
Error: Variable-sized object may not be initialized. But why?
UIImage *img[i] = [UIImage imageNamed:imageName];
This declares a C-style array of size i
and attempts to initialise it with an instance of UIImage
. That doesn't make sense. What are you trying to do? Where is the rest of your code?
Edit:
Okay, I think I see what you are doing. Just get rid of all the places you have [i]
. Inside the loop, you are only dealing with one item at a time, and even if you weren't, that's not how you use arrays.
You may want to try this:
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];
}
You don't need to use img[i] in order to populate a scrollview with UIImageView.
精彩评论