// Declare index in Header.h
index=0;
- (IBAction)next {
index++;
// Set imageCount to as many images as are available
int imageCount=2;
if (index<=imageCount) {
NSString* imageName=[NSString stringWithFormat:@"img%i", index];
[picture setImage: [UIImage imageNamed: imageName]];
}
}
Where do I declare index in my header file and how?
If
indexis used only within the-nextmethod, you can define a static variable.Note that all instances will share the same
index.But I believe it’s better to make
indexas an ivar, e.g.it is automatically initialized to 0 when the instance is constructed, and methods other than
nextcan use theindex. Also, each instance will have its ownindex.