tags:

views:

1316

answers:

1
enter code here- (void)viewDidLoad {

NSMutableArray *imageViewArray= [[NSMutableArray alloc] init];
for ( int i = 1; i < 10 ; i++ ) {

 NSString *imgName = [NSString stringWithFormat:@"pic%i.jpg", i];
 UIImage *img = [UIImage imageNamed:imgName];
 [imageViewArray addObject:img];
} 
self.gallery = imageViewArray;
[imageViewArray release];


NSString *p1 = [NSString stringWithFormat:@"p1.jpg"];
NSString *p2 = [NSString stringWithFormat:@"p2.jpg"];
NSString *p3 = [NSString stringWithFormat:@"p3.jpg"];
NSString *p4 = [NSString stringWithFormat:@"p4.jpg"];
NSString *p5 = [NSString stringWithFormat:@"p5.jpg"];
NSString *p6 = [NSString stringWithFormat:@"p6.jpg"];
NSString *p7 = [NSString stringWithFormat:@"p7.jpg"];
NSString *p8 = [NSString stringWithFormat:@"p8.jpg"];
NSString *p9 = [NSString stringWithFormat:@"p9.jpg"];
UIImage *P1V = [UIImage imageNamed:p1];
UIImage *P2V = [UIImage imageNamed:p2];
UIImage *P3V = [UIImage imageNamed:p3];
UIImage *P4V = [UIImage imageNamed:p4];
UIImage *P5V = [UIImage imageNamed:p5];
UIImage *P6V = [UIImage imageNamed:p6];
UIImage *P7V = [UIImage imageNamed:p7];
UIImage *P8V = [UIImage imageNamed:p8];
UIImage *P9V = [UIImage imageNamed:p9];
NSArray *imageViewArray2 = [[NSArray alloc] initWithObjects:P1V,P2V,P3V,P4V,P5V,P6V,P7V,P8V,P9V,nil];
self.gallery2 = imageViewArray2;
[imageViewArray2 release];

NSArray *array = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",nil];
self.list = array;
[array release];

[super viewDidLoad];

}

+2  A: 

What you should be doing is putting the filenames in an array and simply replacing that variable inside a loop.

Here's some code to demonstrate that:

NSArray *dayStrings = [NSArray arrayWithObjects: @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", nil];
NSArray *timeStrings = [NSArray arrayWithObjects: @"9 AM", @"10 AM", @"11 AM", @"12 PM", @"1 PM", @"2 PM", @"3 PM", @"4 PM", @"5 PM", nil];

int i;
NSMutableAttributedString *day, *time;

for(i = 0; i < HORIZONTAL_CELL_COUNT; i++)
{
  day = [[[NSMutableAttributedString alloc] initWithString:[dayStrings objectAtIndex:i] attributes:attributes] autorelease];
  [days addObject:day];
}

for(i = 0; i < VERTICAL_CELL_COUNT; i++)
{
  time = [[[NSMutableAttributedString alloc] initWithString:[timeStrings objectAtIndex:i] attributes:attributes] autorelease];
  [times addObject:time];
}
alamodey