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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:13:59+00:00 2026-06-02T18:13:59+00:00

I am trying to set up my TableView, and I am having trouble. The

  • 0

I am trying to set up my TableView, and I am having trouble. The values of my NSArray is different from each other. I know this is hard to understand, but i will try my best to explain.
For example

-(void)setUpContacts{
//set up the contacts
NSString *string = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

letterArray = [[NSMutableDictionary alloc]init];

Contacts *contact = [[Contacts alloc]init];
contactNumbers = [contact phoneNumbers];

for (NSDictionary* info in contactNumbers) {
    firstLetter = [info objectForKey:@"lastName"];
    index = @"_";
    if([firstLetter length] > 0){
        firstLetter =[firstLetter substringToIndex:1];
        firstLetter= [firstLetter capitalizedString];
        NSRange range = [string rangeOfString:firstLetter];
        if(range.length >= 0){
            index= firstLetter;
        }
    }
    if(![letterArray objectForKey:index]){

        [letterArray setValue:[NSMutableArray array] forKey:index];
    }
    [[letterArray objectForKey:index] addObject:info];    
}NSLog(@"%@",letterArray);}

-(NSArray *)getLetterArraycount{
NSMutableArray *countArray = [[NSMutableArray alloc]init];
NSNumber *subCount;

for(id key_main in letterArray){
    subCount = 0;

    for(id key_sub in [letterArray objectForKey:key_main]){
        subCount = [NSNumber numberWithInt:[subCount intValue]+1];
    }
    [countArray addObject:subCount];

}
return countArray;

}

- (void)viewDidLoad{
[super viewDidLoad];
[self setUpContacts];
countArrays = [self getLetterArraycount];    
indexPaths = [[NSMutableDictionary alloc]init];   

NSArray *temp = [letterArray allKeys];
NSLog(@"%@",temp);

NSLog(@"%@",countArrays);

//set up the tableView
self.myTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
self.title = @"Select Friends";
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:myTableView];}

and it logs like this in the Console

    C =     (
            {
        firstName = Alex;
        kind = Mobile;
        lastName = Chang;
        name = "Alex Chang (Mobile)";
        number = "(555) 555-5555";
    },
            {
        firstName = YuYu;
        kind = Mobile;
        lastName = Chen;
        name = "YuYu Chen (Mobile)";
        number = "(408) 112-2334";
    },
            {
        firstName = Chris;
        kind = Mobile;
        lastName = Choi;
        name = "Chris Choi (Mobile)";
        number = "(999) 999-9999";
    },
            {
        firstName = Kevin;
        kind = Mobile;
        lastName = Chung;
        name = "Kevin Chung (Mobile)";
        number = "1 (231) 241-2312";
    }
);
H =     (
            {
        firstName = Danny;
        kind = Mobile;
        lastName = Huang;
        name = "Danny Huang (Mobile)";
        number = "(408) 599-9770";
    },
            {
        firstName = Ice;
        kind = Mobile;
        lastName = Huang;
        name = "Ice Huang (Mobile)";
        number = "(408) 444-4444";
    }
);
K =     (
            {
        firstName = Will;
        kind = Mobile;
        lastName = King;
        name = "Will King (Mobile)";
        number = "(415) 123-4567";
    }
);
L =     (
            {
        firstName = "";
        kind = iPhone;
        lastName = LastName;
        name = " LastName (iPhone)";
        number = "(408) 123-2555";
    },
            {
        firstName = david;
        kind = Mobile;
        lastName = lub;
        name = "david lub (Mobile)";
        number = "(666) 666-1111";
    }
);
P =     (
            {
        firstName = Jennifer;
        kind = Mobile;
        lastName = Pie;
        name = "Jennifer Pie (Mobile)";
        number = "(666) 666-6666";
    }
);
S =     (
            {
        firstName = Martin;
        kind = Mobile;
        lastName = Shen;
        name = "Martin Shen (Mobile)";
        number = "(415) 333-1234";
    },
            {
        firstName = Francis;
        kind = Mobile;
        lastName = Shung;
        name = "Francis Shung (Mobile)";
        number = "(408) 345-6789";
    }
);
V =     (
            {
        firstName = Brian;
        kind = Mobile;
        lastName = Vu;
        name = "Brian Vu (Mobile)";
        number = "(408) 234-5678";
    }
);
Y =     (
            {
        firstName = Qiu;
        kind = Mobile;
        lastName = Yang;
        name = "Qiu Yang (Mobile)";
        number = "(408) 567-8901";
    }
);
Z =     (
            {
        firstName = Joy;
        kind = Mobile;
        lastName = Zhou;
        name = "Joy Zhou (Mobile)";
        number = "(408) 765-4321";
    }
);
"_" =     (
            {
        firstName = FirstName;
        kind = Mobile;
        lastName = "";
        name = "FirstName  (Mobile)";
        number = "1 (408) 234-5141";
    }
);

}

2012-04-26 16:14:05.195 UpOut[2693:15803] (
L,
Y,
V,
"_",
Z,
S,
K,
C,
P,
H

MY Question is why doesnt it log “C” first, but instead it Logged “L”

  • 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-02T18:14:02+00:00Added an answer on June 2, 2026 at 6:14 pm

    Sounds like you need to learn how to use “NSSortDescriptor“ (I’ve linked the documentation for you).

    Here is a related question that might have some useful sample code you can refer to. The key you would want to sort on, in your case, would be the lastName value of each NSDictionary entry.

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

Sidebar

Related Questions

Trying to set up Cancan within an app of mine and having trouble with
I'm having trouble trying to scroll up a tableView when the user start editing
Hey I'm having trouble trying to figure this one out. UITableView has a method
I'm trying to set a segmented control on each cell of the tableView of
I'm trying to set the image for the cell in a tableview by code.
I'm trying to set array values in UITableViewCell at cellAtRowIndexPath - method, but it's
I have downloaded TableView sample code '4_TableViewCellSubviews' from internet. I am trying to run
I'm trying to figure out where to properly set tableView.rowHeight. Currently I have it
Possible Duplicate: sectioned UITableView sourced from a pList I am having a hard time
I'm trying to set the Backgroundcolor of my grouped tableview to a color with

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.