views:

226

answers:

2

Hey everyone- I need some help. I have a UITableView that has cells that hold the title of an entity. Naturally, inside of a UITableView Section Header, it orders all cells or titles alphabetically by name. Each of these entities have several attributes, and one is a numerical value representing priority. Is there a way to make it so that inside of the UITableView Section Header the cells that still hold the title attribute of the entity is sorted instead by the priority value? Making it so that the entity with the highest priority value is higher than lower ones? I just haven't had tons of experience with this so I really appreciate any help or direction. Thanks again.

Sorry, just to clarify: The entity whose title is shown in the tableviewcells is created and editable by the user. So they can click to add a new object and then are able to enter specific information about the object. Like name, place, priority(of relevance or importance) etc. All I want to be able to do is sort by that priority value, rather than alphabetically. Sorry if it is still ambiguous...

A: 

Apply an NSSortDescriptor to the NSArray you're using as the table view's data source. Apple's documentation provides clear examples.

Alex Reynolds
A: 

If you're using CoreData, as it sounds like you are, set the sortDescriptors property of your NSFetchRequest like so:

NSArray *sortDescriptors = [NSArray arrayWithObject:
    [[[NSSortDescriptor alloc] initWithKey:@"priority" ascending:NO] autorelease]];
[fetchRequest setSortDescriptors:sortDescriptors];
Ian Henry