Objective c 单击“下一步”按钮时,如何逐个显示下一个图像?
我是iPhone的初学者。我已获取阵列,因为我已传递所有图像,但单击“下一步”按钮时图像未显示 我的代码是Objective c 单击“下一步”按钮时,如何逐个显示下一个图像?,objective-c,ios5,Objective C,Ios5,我是iPhone的初学者。我已获取阵列,因为我已传递所有图像,但单击“下一步”按钮时图像未显示 我的代码是 images= [[NSArray arrayWithObjects: [UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"], [UIImage imageNamed:@"3
images= [[NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
nil] retain];
-(IBAction)Next
{
currentImage++;
if(currentImage +1>=[images count])
{
currentImage=0;
NSLog(@"print:%@",currentImage);
UIImage *img=[images objectAtIndex:currentImage];
[animalphoto setImage:img];
}
else
{
currentImage++;
NSLog(@"hello:%@",currentImage);
}
}
但是下一步按钮经常单击时间按钮图像不经常显示时间,所以给出任何建议和源代码只要将if语句的两行放在nslog后面的else部分,问题就解决了您的代码,仅当currentImage index计数器高于在索引0处显示图像的计数(换句话说)时,才会显示新图像;逻辑是不正确的。u应仅在计数器等于计数时将其重置为0,并使用新索引显示新图像。什么是
currentImage
?您正在更改它,就好像它是一个数字,但将其打印为一个对象。