我有iPhone的初学者。我有一个阵列中的图像,但它返回NULL单击下一个按钮时如何逐个显示图像?
我有使用此代码
- (void)viewDidLoad
{
[super viewDidLoad];
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>=[images count])
{
currentImage=0;
}
UIImage *img=[images objectAtIndex:currentImage];
[animalphoto setImage:img];
NSLog(@"print:%@",currentImage);
}
第一次点击按钮图像显示,但第二次不显示图像和返回NULL值..给出任何建议,并源代码适用于我们的代码。
这将导致异常;测试应该是:if(currentImage> = [images count])。 – trojanfoe 2012-07-06 11:07:51
trojanfoe你正确 – 2012-07-06 11:15:52