简体   繁体   中英

display data in alphabetical order iphone

如何在UITableView中按字母顺序显示xml解析的数据?

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM