I have a tableView with several Sections being populated from a plist of NSDictionaries
How do I have it arrange the sections in the order they are in in the NSDictionary instead of alphabetically?
I have a tableView with several Sections being populated from a plist of NSDictionaries
How do I have it arrange the sections in the order they are in in the NSDictionary instead of alphabetically?
NSDictionary is unordered. You should use an NSArray (or std::vector
, or std::map
, etc.) as the data source.
To get the keys, use -allKeys
. To get a sorted array from it, use -sortedArrayUsingSelector:
.
I improvised a solution. I added a "01", "02", "03" etc to the beginning of each dictionary name then just added the code to remove those two characters before displaying it:
-(NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section{
NSString *key = [keys objectAtIndex:section];
key = [key substringFromIndex:2];
return key;
}