【发布时间】:2011-03-26 22:54:27
【问题描述】:
感谢@JFoulkes,我的应用程序可以在单击下一步按钮时显示数组中的第一个图像。但是,当我再次单击它时,它不会显示数组中的下一个图像。这让我相信我的下一个按钮的 IBAction 不太正确。
这是我到目前为止的代码......
在我的 .h 文件中我已经声明:
IBOutlet UIImageView *imageView;
NSArray *imageArray;
NSInteger currentImage;
我还补充说:
-(IBAction) next;
在我的 .m 文件中:
-(void) viewDidLoad;
{
imageArray = [[NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
nil] retain];
}
这是我的 IBAction,它只显示数组中的第一个图像 (1.png),再次单击时不会将 UIImageView 更改为第二个数组图像 (2.png):
-(IBAction)next {
if (currentImage + 1 == [imageArray count])
currentImage = 0;
UIImage *img = [imageArray objectAtIndex:currentImage];
[imageView setImage:img];
currentImage++;
}
根据代码,如何更改 IBAction 以在单击后成功遍历数组中的图像?
【问题讨论】:
标签: iphone objective-c xcode ios4