我知道这个问题被问了很多次,但我没有找到任何解决我的问题的方法。我在 ViewDidLoad 上声明计数器为 0,
- (void)viewDidLoad
{
[super viewDidLoad];
counter = 0;
[stgImage1 setImage:[UIImage imageNamed:[imageStr objectAtIndex:counter]]];
}
这是我的下一个也是上一个动作,
-(void)btnClicked:(UIButton*)btn{
if (btn.tag==1) {
if (counter < [textStr count]-1) {
counter++;
NSLog(@"%i", counter);
[stgImage1 setImage:[UIImage imageNamed:[imageStr objectAtIndex:counter]]];
}
if(counter > [textStr count]) {
counter = 0; //to loop continuously
}
}
else{
if (counter>0) {
counter--;
NSLog(@"%i", counter);
[stgImage1 setImage:[UIImage imageNamed:[imageStr objectAtIndex:counter]]];
}
}
问题:这部分在我的情况下不起作用,即这里没有发生连续循环
if(counter > [textStr count]) {
counter = 0; //to loop continuously
}
请帮我!