I want to display data in UITableView in reverse order. I manage to do it with little effort but can any one provide a better way to do it. Thanks in advance.
Use -[NSArray reverseObjectEnumerator]
:
NSArray * a = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSArray * reverse = [[a reverseObjectEnumerator] allObjects];
NSLog(@"%@", reverse); //logs "c, b, a"
Well i dont know what your code is but you can do something like this
cell.title = [anarray objectAtIndex:(anarray.count - indexPath.row - 1)];
Hope this may works. Cheers.
There is a much easier solution, if you take advantage of the built-in reverseObjectEnumerator method on NSArray, and the allObjects method of NSEnumerator:
NSArray* reversedArray = [[startArray reverseObjectEnumerator] allObjects];
精彩评论