1

在我的应用程序中,我有 4 张图像。我想在每次点击时显示不同的图像。如何在每次点击时显示不同的图像?

这是我的单张图片代码:

-(void)removeImageView
{   
    rightongbanner.image=Nil;
}

-(void)alertshow
{
    rightongbanner.image=[UIImage  imageNamed:@"correct.png"];
    timer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(removeImageView) userInfo:nil repeats:NO];
    [aplayer play];
}

rightongbanner.image中,我想在第一次单击时显示 img1,在第二次单击时显示 img2。我怎样才能做到这一点?

4

1 回答 1

2

试试这样

.h

int a;

.m

-(void)loadView  {
    a=0;
}

-(void)alertshow
{
   if((a%4)==0)
       rightongbanner.image=[UIImage  imageNamed:@"correct1.png"];
   if((a%4)==1)
       rightongbanner.image=[UIImage  imageNamed:@"correct2.png"];
   if((a%4)==2)
       rightongbanner.image=[UIImage  imageNamed:@"correct3.png"];
   if((a%4)==3)
       rightongbanner.image=[UIImage  imageNamed:@"correct4.png"];

  timer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(removeImageView) userInfo:nil repeats:NO];
     [aplayer play];
  a++;
}
于 2012-12-27T10:34:22.610 回答