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 6930375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:26:20+00:00 2026-05-27T11:26:20+00:00

Having a little issue with NSDictionary and sorting. I’ve read a few posts on

  • 0

Having a little issue with NSDictionary and sorting. I’ve read a few posts on here about using certain methods such as sortedArrayUsingSelector and keysSortedByValueUsingComparator but cannot quite grasp it. At the moment I have a Table View Controller displaying some data correctly. The only issue I have is the order it is displaying it (or rather, the order of the sections).

In the declaration file:

@interface SettingsTableViewController : UITableViewController {
    NSDictionary *tableContents;
    NSArray *keys;
}
@property (nonatomic,retain) NSDictionary *data;
@property (nonatomic,retain) NSArray *keys;
@end

And the implementation file, for viewDidLoad:

NSArray *arrayTemporary1 = [[NSArray alloc]initWithObjects:@"Settings 1",@"Setting 2",@"Setting 3",@"Setting 4",nil];
NSArray *arrayTemporary2 = [[NSArray alloc]initWithObjects:@"Enable Gestures",nil];
NSArray *arrayTemporary3 = [[NSArray alloc]initWithObjects:@"Instructions",@"Frequently Asked Questions",@"About",nil];

NSDictionary *temporary =[[NSDictionary alloc]initWithObjectsAndKeys:arrayTemporary1,@"Settings",arrayTemporary2,@"Application",arrayTemporary3,@"Information",nil];
self.tableContents = temporary;

self.keys = [self.tableContents allKeys];

[temporary release];
[arrayTemporary1 release];
[arrayTemporary2 release];
[arrayTemporary3 release];

Individual cell data is accessed from an array NSArray *listData =[self.tableContents objectForKey:[self.keys objectAtIndex:[indexPath section]]]; inside the cellForRowAtIndexPath method.

Whilst this works fine, the issue I’m having is that rather than displaying the sections in the order that it is written in temporary, it does so randomly. Would appreciate some guidance.

  • 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-05-27T11:26:21+00:00Added an answer on May 27, 2026 at 11:26 am

    Dictionaries do not guarantee ordering, so tableContents has no memory of the order in which you added the arrays to it. You should keep ordered data in NSArrays.

    Put the titles of the sections in a separate NSArray. Then use the dictionary you have to look up the data for the cells when you need to. This lets you keep the titles in the order you want, and still have a way to find the values in the dictionary.

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

Sidebar

Related Questions

i'm having a little issue with doctrine using symfony 1.4 (I think it's using
I've been having a little issue with image URLs. Usually I wouldn't care about
Basically I'm having a little issue here. I have a superclass and a subclass.
Im having a little issue with using more than 1 UITableView on a view.
I'm having a little issue with the colorbox when using it in a facebook
I'm having a little issue with getting a value of field in HTML using
I am having a little issue here. I am a web development major and
I am having a little issue with echoing javascript dynamically via php. Here is
Hopefully someone can shed a little light on an issue that I'm currently having
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to

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.