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

  • Home
  • SEARCH
  • 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 7861637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:48:22+00:00 2026-06-02T22:48:22+00:00

I am having trouble returning the numberofSections/numberofRows. I have a dictionary full of data

  • 0

I am having trouble returning the numberofSections/numberofRows. I have a dictionary full of data

-(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);}

and it NSLogs with this

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";
    }
);

for the -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; method
how do i retrieve the number of sections for index;

and for the -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; method, how do i retreive the number of rows in the section?

EDIT

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *array = [letterArray mutableCopy];
return [[array objectAtIndex:section]count];}

and it gives me this error: -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8434cc0

Thank you in advance

  • 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-02T22:48:23+00:00Added an answer on June 2, 2026 at 10:48 pm

    for -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView you should do something like this:

    return [letterArray count];
    

    for -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section you should do something like this:

    NSArray *array = letterArray;
    return [[array objectAtIndex:section] count];
    

    EDIT
    Try this:

    -(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;
    }
    

    You should call it once and save it to a class variable and call it like this for sections:

    [countArray count];
    

    And for the rows in a section like this:

    [[countArray objectAtIndex:section] intValue];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble returning data from my sql-server database to an aspx page
I'm having trouble developing a standard for returning data from user functions passed and
I'm having trouble returning data from my controller using an ajax post function. What
I am having some trouble returning matrix data from one method to the main
I am having trouble returning a list given a model. The model I have:
After adding the rspec test provided in Listing 7.32 rspec is having trouble returning
I'm having some trouble returning multiple values in this program that calculates min, max,
Having trouble to start a new activity after progressbar have loaded. Im getting stucked
Having trouble with MKAnnotation. Have a custom pinview and works fine for the first
I'm having trouble returning arrays from a custom method. It compiles fine but I

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.