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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:34:33+00:00 2026-05-25T21:34:33+00:00

I have a sectioned UITableView being populated by data from a pList. The root

  • 0

I have a sectioned UITableView being populated by data from a pList. The root of the pList is a dictionary, each key of this dictionary is loaded into an array, which is used to define the section headings (and presumably order).

Currently my sections appear in the table in a random order, I would like to order them as they appear in the pList, or at least fake it by ordering the sections alphabetically.

I understand that dictionaries have no order, which is why the output does not reflect the pList order, but I would prefer not to change the root to an array as it requires me to rewrite chunks of my app, plus Xcode 4 seems to prefer you using a dictionary as the root. Of course if changing the pList structure is the best method, I’ll go with that.

pList sample:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"   "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Section A</key>
    <array>
        <dict>
            <key>Details</key>
            <string>Details Here...</string>
            <key>Image</key>
            <string>X.png</string>
            <key>Name</key>
            <string>Person X</string>
        </dict>
        <dict>
            <key>Details</key>
            <string>Details Here...</string>
            <key>Image</key>
            <string>Y.png</string>
            <key>Name</key>
            <string>Person Y</string>
        </dict>
    </array>
    <key>Section B</key>
    <array>
        <dict>
            <key>Details</key>
            <string>Details Here...</string>
            <key>Image</key>
            <string>Z.png</string>
            <key>Name</key>
            <string>Person Z</string>
        </dict>
    </array>
</dict>

Code within ‘TableViewController.m’:

- (void)viewDidLoad {

[super viewDidLoad];

NSString *path = [[NSBundle mainBundle] pathForResource:@"Team" ofType:@"plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.teamDictionary = tempDict;
[tempDict release];

NSArray *tempArray = [[NSArray alloc] init];
self.teamArray = tempArray;
[tempArray release];

self.teamArray = [self.teamDictionary allKeys];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return [self.teamArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [[self.teamDictionary valueForKey:[self.teamArray objectAtIndex:section]] count];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

// this is here because I am altering the appearance of the header text
UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, tableView.bounds.size.width, 44.0)] autorelease];

UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];

// some custom formatting stuff has been removed from here...

headerLabel.text = [self.teamArray objectAtIndex:section];
[customView addSubview:headerLabel];
[headerLabel release];

return customView; 
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [teamArray objectAtIndex:section];
NSArray *teamMember = [teamDictionary objectForKey:key];

static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease];
}

// Configure the cell...

NSDictionary *name = [teamMember objectAtIndex:row];
cell.textLabel.text = [name objectForKey:@"Name"];
}
  • 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-25T21:34:33+00:00Added an answer on May 25, 2026 at 9:34 pm

    I can think of two options:

    1. Use an array as the root of your plist. Each item in the array would be a dictionary, with two keys: name/title and items. Name/title would be a string and items would be an array.

    2. Keep your plist as is, order the keys alphabetically:

      NSArray *sortedKeys = [[dict allkeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my uitable data being populated for the current section inside numberOfRowsInSection .
I have a table being generated from an array of NSManagedObjects. This works fine
I have a sectioned UITableView using dictionaries adapting code from a tutorial (I don't
I'm stuck in a rut over implementing a sectioned plist into a UITableView. My
I have a UITableView that's populated using core data & sqlite. I'd like to
I have a UITableView with two sections: free and paid. Each section has a
I'm having trouble understanding coredata with my uitableview. I have rows being deleted and
I have a UITableView inside of a View created from a NIB. the table
Hi All I have a UITableView with the list of items fetched from sqllite.
I have UITableView being pushed to UINavigationController. I need to add a UIToolBar 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.