Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:35:17+00:00 2026-06-04T04:35:17+00:00

Currently I have a NSMutableArray that loads from NSUserDefaults in my app and feeds

  • 0

Currently I have a NSMutableArray that loads from NSUserDefaults in my app and feeds the data to my UITableView. The NSMutableArray consists of NSDictionarys which consist of 5 or 6 keys each.

Then in the view where the UITableView is, I have a UISegmentedControl where the user can then sort the UITableView based upon Date or some other things.

So when they click the date segment, I execute this code:

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"Date" ascending:NO];
[self.cellArray sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];

The sorting itself works as I can see self.cellArray being sorted through NSLogs. Although when I call my tableview to reloadData, none of the NSDictionarys actually re-sort in the tableview itself. So programmatically they are being sorted but not in the UI which is extremely odd.

If use this for statement right after the code I posted above:

for (NSDictionary *dict in self.cellArray) {
            NSLog(@"DateKey: %@", [dict objectForKey:@"Date"]);
}

This is what my NSLogs look like if I do ascending:YES :

2012-05-20 13:48:21.008 App[71308:707] DateKey: 2012-05-13 18:19:22 +0000
2012-05-20 13:48:21.009 App[71308:707] DateKey: 2012-05-13 18:19:29 +0000
2012-05-20 13:48:21.009 App[71308:707] DateKey: 2012-05-15 01:54:13 +0000
2012-05-20 13:48:21.010 App[71308:707] DateKey: 2012-05-15 04:01:15 +0000
2012-05-20 13:48:21.011 App[71308:707] DateKey: 2012-05-16 04:08:20 +0000
2012-05-20 13:48:21.012 App[71308:707] DateKey: 2012-05-16 04:13:59 +0000
2012-05-20 13:48:21.012 App[71308:707] DateKey: 2012-05-16 04:32:29 +0000
2012-05-20 13:48:21.013 App[71308:707] DateKey: 2012-05-16 04:32:38 +0000

If I do ascending:NO this is what my NSLogs look like:

2012-05-20 13:56:25.956 App[71468:707] DateKey: 2012-05-16 04:32:38 +0000
2012-05-20 13:56:25.960 App[71468:707] DateKey: 2012-05-16 04:32:29 +0000
2012-05-20 13:56:25.961 App[71468:707] DateKey: 2012-05-16 04:13:59 +0000
2012-05-20 13:56:25.961 App[71468:707] DateKey: 2012-05-16 04:08:20 +0000
2012-05-20 13:56:25.962 App[71468:707] DateKey: 2012-05-15 04:01:15 +0000
2012-05-20 13:56:25.962 App[71468:707] DateKey: 2012-05-15 01:54:13 +0000
2012-05-20 13:56:25.963 App[71468:707] DateKey: 2012-05-13 18:19:29 +0000
2012-05-20 13:56:25.964 App[71468:707] DateKey: 2012-05-13 18:19:22 +0000

So as you can see, the sorting indeed works properly but once I do reloadData after that code, my UITableView does not re-order the cells based upon the Date key.

My tableview is in fact connected in IB and is not nil. I do have a setter and getter for it to if that matters.

Does anyone have any idea why this happening? Or do you need more context/code?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:35:18+00:00Added an answer on June 4, 2026 at 4:35 am

    I’d be inclined to put your logging statement …

    for (NSDictionary *dict in self.cellArray)
        NSLog(@"DateKey: %@", [dict objectForKey:@"Date"]);
    

    in, right after you invoke sortUsingDescriptors as well in your cellForRowAtIndexPath method. I’d also put a NSLog statement right where cellArray is getting initialized (to make sure that you’re not accidentally invoking that again … easy to do if your routines get complicated).

    I have to believe that the order in cellForRowAtIndexPath will not reflect the order you got immediately after your sort. Assuming this is the case, either cellArray is getting reset somewhere (i.e. where do you populate it? in viewDidLoad or somewhere else?), or your sortUsingDescriptors is not getting invoked like you think it is.

    Just start putting break points and/or debugging messages in your various routines. It’s got to be something simple. I just did a test of reloading where I resort as I reload, and the sort orders are being preserved. So it’s got to be something simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a function written called saveWorkout that saves an NSMutableArray to another
Scenario I have made a phonegap 1.0.0 app which loads the current location via
I have an application which needs to load data from a remote server (businesses
Currently, I have a tableView which is loaded from the following array called exerciseArray
Currently, I have edited a delegate function that adds Exercise objects to an NSMutableArray.
I currently have 4 textboxes which will be used to store an ip address.
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I currently have links w/ class=ajax that I want to retrieve the element with
Im currently working on an app which lists a set of objects in a
I have a Cocoa project with an object that holds information from a SQLite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.