You can try the following:
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 do not need to use img [i] to populate a scrollview with a UIImageView.
source share