How to put condition for an array to display the images. if it encounters last element of array it should go to previous order i.e., consider array have some 5 elements. 0 1 2 3 4 i need to traverse from 0 1 2 3 4 after encounter 5th object now to it should traverse to 4 3 2 1 0. How to put this logic?
Asked
Active
Viewed 110 times
0
-
Possible duplicated of : http://stackoverflow.com/questions/586370/how-can-i-reverse-a-nsarray-in-objective-c – Sunny Shah May 26 '14 at 06:29
-
r u trying for animation? – Warif Akhand Rishi May 26 '14 at 06:37
-
Can you provide more information on what you are trying to achieve. Do you want to reverse direction again when reach the first element? – Paulw11 May 26 '14 at 06:50
2 Answers
0
I just put my logic
for(int i = 0 ; i < myArray.count; i ++)
{
NSLog(@"%d", i);
if(i == myArray.count -1)
{
for(int j = myArray.count-1 ; j >= 0; j --)
{
NSLog(@"%d", j);
}
}
}
Try with it, its working well. :)

iPatel
- 46,010
- 16
- 115
- 137
0
The easiest way is doing 2 loops.
for (NSInteger i = 0;i < [array count]; i++)
{
NSLog(@"%@", [array objectAtIndex:i]);
}
for (NSInteger i = [array count] - 1;i >= 0; i--)
{
NSLog(@"%@", [array objectAtIndex:i]);
}

Gonzo
- 1,533
- 16
- 28