I have this code:
- (IBAction)next {
// <-- here
index++;
// Set imageCount to as many images as are available
int imageCount=3;
if (index<=imageCount) {
NSString* imageName=[NSString stringWithFormat:@"img%i.jpg", index];
[picture setImage: [UIImage imageNamed: imageName]];
}
}
- (IBAction)prev {
// <-- here
index--;
// Set imageCount to as many images as are available
int imageCount=3;
if (index > 1) {
NSString* imageName=[NSString stringWithFormat:@"img%i.jpg", index];
[picture setImage: [UIImage imageNamed: imageName]];
}
}
The first one is linked to a button and works fine and changes the image forward. The second one is linked to another button, but will only go b开发者_运维知识库ackwards one image. I am really stuck and I am in need of severe help. Please could someone help me. (index is a property and sythesized) ImageCount is not. There is also no list of images. The images are: img1.jpg img2.jpg img3.jpg
Thanks.
If your image names are 1-based (there's only img1.jpg, img2.jpg and img3.jpg), perhaps your -prev action should check if (index >= 1)
?
There are much easier ways of doing this if you only ever have the same three images, however. Maybe you should explain your overall goal (from a very high level - what you want your app to do) and the community can help you choose a better path.
精彩评论