Alan
Alan

Reputation: 9471

NSSortDescriptor Not Working to Organize TableView

I am working on sorting my TableView cells and it is not working for some reason. I had an earlier revision of the exact same code and the exact same PLIST but I could have sworn it worked for several months. Now it refuses to sort.

Sorting Code inside the numberOfRowsInSection method:

NSString *date = [self.months objectAtIndex:sectionNumber];
NSDictionary *monthData = [self.sportDictionary objectForKey:date];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey: nil ascending: YES];
NSArray *days = (NSArray *)[[monthData allKeys]sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor2]];

for(int x = 0; x < [days count]; x++)
{
    NSLog(@"Day: %@", [days objectAtIndex:x]);
}

When I look at the output of the NSLog, it is not right. Getting 15, 22, 29, 3, 8

The part of the PList that it's sorting is as shown:

<dict>
<key>1 September 2012</key>
<dict>
    <key>3</key>
    <array>
        <string>Georgia Tech (Orange Effect)</string>
        <string>8:00 PM </string>
        <string>Home</string>
    </array>
    <key>8</key>
    <array>
        <string>Austin Peay (White Effect)</string>
        <string>1:30 PM</string>
        <string>Home</string>
    </array>
    <key>15</key>
    <array>
        <string>Pittsburgh (White Effect)</string>
        <string>12:00 PM</string>
        <string>Away</string>
    </array>
    <key>22</key>
    <array>
        <string>Bowling Green</string>
        <string>TBA</string>
        <string>Home</string>
    </array>
    <key>29</key>
    <array>
        <string>Cincinnati</string>
        <string>TBA</string>
        <string>Away</string>
    </array>
</dict>

Thank you, I really appreciate your help!

Upvotes: 0

Views: 171

Answers (1)

tarheel
tarheel

Reputation: 4797

Best bet is to take the NSDates that you already have, extract the day components as NSNumbers or ints and then sort and continue with what you already have. Here is something that might help you on extracting the day component of the NSDate.

Upvotes: 1

Related Questions