display data in alphabetical order iphone

前端 未结 3 2074
逝去的感伤
逝去的感伤 2020-12-20 07:01

How to display xml parsed Data in UITableView In alphabetical order.?

相关标签:
3条回答
  • 2020-12-20 07:40
    NSSortDescriptor *sorter;
    
    sorter = [[NSSortDescriptor alloc]initWithKey:@"Category" ascending:YES];
    
    NSArray *sortDescriptors = [NSArray arrayWithObject:sorter];
    
    [categoryListArray sortUsingDescriptors:sortDescriptors];
    
    [sorter release];
    

    Try This

    0 讨论(0)
  • 2020-12-20 07:41

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

    0 讨论(0)
  • 2020-12-20 07:43

    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

    0 讨论(0)
提交回复
热议问题