Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 单击“下一步”按钮时,如何逐个显示下一个图像?_Objective C_Ios5 - Fatal编程技术网

Objective c 单击“下一步”按钮时,如何逐个显示下一个图像?

Objective c 单击“下一步”按钮时,如何逐个显示下一个图像?,objective-c,ios5,Objective C,Ios5,我是iPhone的初学者。我已获取阵列,因为我已传递所有图像,但单击“下一步”按钮时图像未显示 我的代码是 images= [[NSArray arrayWithObjects: [UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"], [UIImage imageNamed:@"3

我是iPhone的初学者。我已获取阵列,因为我已传递所有图像,但单击“下一步”按钮时图像未显示

我的代码是

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
?您正在更改它,就好像它是一个数字,但将其打印为一个对象。