Saraswathi Saraswathi - 6 months ago 29
Objective-C Question

Array Index in Descending Order

I am developing an camera app ,and showing the taken photos in thumbnail view with the numbers .i am displaying the numbers from array index value in ascending order.Like this.In this image numbers are in 1 , 2, 3, i want the numbers in 3 ,2 ,1
Now i want the numbers in descending order.Please help me to do this .my code is ..

NSString *the_index_path = [NSString stringWithFormat:@"%li", (long)indexPath.row+1];
Cell.waterMark_lbl.text = the_index_path;

this is code is in cellforitem at index method in collection view .
Thanks in advance !!!


You can rearrange the data model in reverse order and from there the data will be displayed. Plan B, more convoluted, it would not change the order. When you have to show the cell 0, display the last, with cell 1 shows the penultimate, etc. You should generate a new indexPath every time you have to show the data.

The other option I understand is that for the first cell you want to show the last number. The operation would be similar, but without generating the new indexPath. You have to do the subtraction of the total number of elements. Suppose the total number of elements is NUMBER_OF_ELEMENTS

Cell.waterMark_lbl.text = [NSString stringWithFormat:@"%li",NUMBER_OF_ELEMENTS - indexPath.row ]

In the case of reorder the cells without reorder the data, you have to créate a new indexPath and get the data value for display

NSIndexPath *ip = [NSIndePath indexPathForRow:NUMBER_OF_ELEMENTS - indexPath.row inSection:indexPath.section ]

sorry for lexical errors. I have the objective c somewhat forgotten