How to display xml parsed Data in UITableView In 开发者_StackOverflow中文版alphabetical order.?
In order to display/arrange your data in alphabetical which in a array you have to use NSSortDescriptor
you have to make the object of this NSSortDescriptor
class and give data here which you are fetching from XML
NSSortDescriptor *itemXml = [[NSSortDescriptor alloc] initWithKey:@"itemName" ascending:YES];
Now suppose you have an array sortDescriptors
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:itemXml,nil];
[yourArray sortUsingDescriptors:sortDescriptors];
Now give the yourArray to your UITableView
delegate methods...... you will get the sorted data on table
NSSortDescriptor *sorter;
sorter = [[NSSortDescriptor alloc]initWithKey:@"Category" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sorter];
[categoryListArray sortUsingDescriptors:sortDescriptors];
[sorter release];
Try This
Actually there are lots of different ways to sort arrays.
Sort descriptors are only one example.
Others are sortedArrayUsingComparator, sortedArrayUsingFunction:context, sortedArrayUsingSelector, and new to Mac OS 10.6 and iOS 4.0, sortedArrayWithOptions:usingComparator.
Those are NSArray methods that return a sorted array.
NSMutableArray also has variations on those methods that sort the mutable array "in place".
精彩评论