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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:36:31+00:00 2026-05-28T02:36:31+00:00

I’m driving myself crazy trying to figure out how to implement tableView numberofRowsinSection and

  • 0

I’m driving myself crazy trying to figure out how to implement tableView numberofRowsinSection and was hoping I could get some tips or suggestions. I feel like I’ve over-complicated the entire thing. Let me start by posting the converted xml data that is now an NSDictionary.

{
    "@body" = "";
    "@class_id" = "";
    "@title" = Discussions;
    "@type" = "Discussion Block";
},
{
    "@body" = "";
    "@class_id" = "";
    "@col" = 1;
    "@title" = YouTube;
    "@type" = "Youtube Block";
    item =     {
        "@body" = "http://www.youtube.com/watch?v=vDWhfsQHq1o&ob=av3e";
        "@title" = "Gavin DeGraw - Not Over You";
        "@type" = link;
    };
},
{
    "@body" = "";
    "@class_id" = "";
    "@title" = Calendar;
    "@type" = "Calendar Block";
},
{
    "@body" = "<p>  homework test</p> ";
    "@class_id" = "";
    "@title" = Homework;
    "@type" = "File Block";
    item =     (
                {
            "@body" = "https://MYDOMAIN.com/securelink;
            "@title" = "crashreport.rtf";
            "@type" = file;
        },
                {
            "@body" = "mydomain.com/securelink";
            "@title" = "Chem notes sep 26.docx";
            "@type" = file;
    }
);
},
{
    "@body" = "<p>  Link testing</p> ";
    "@class_id" = "";
    "@title" = Links;
    "@type" = "Link Block";
    item =     (
                {
            "@body" = "http://google.com";
            "@title" = Link1;
            "@type" = link;
        },
                {
            "@body" = "http://yahoo.com";
            "@title" = link2;
            "@type" = link;
        },
                {
            "@body" = "http://reddit.com";
            "@title" = link3;
            "@type" = link;
        }
    );
}
)

The above data is the response. The goal for this is to have the first title key be the table headers, and for the second “title” key (inside “item”) to be the rows for their respective sections. In the tableView TitleforHeaderinSection method I simply use this code

for (NSDictionary *roster in response) {
     [blockName addObject:[roster objectForKey@"@title"]];
 }
     return [blockName objectAtIndex:section];

The numberofRowsinSection method is where things get tricky. This is what I tried

for (NSDictionary *myDict in [[response objectAtIndex:section] valueForKeyPath:@"item"]) {
    NSArray *keys = [myDict allKeys];
    if ([keys containsObject:@"@title"]) {
        array3 = [[NSMutableArray alloc] init];
        [array3 addObject:[myDict objectForKey:@"@title"]];
    }
}
 return array3;

The error that I’m getting is that myDict is an NSString and allKeys can’t be used on it. I’m not sure why this is happening because when I change it to objectAtIndex:1 and log it the allKeys method works. I’m also pretty sure this isn’t the best way to find the number of rows needed in each section, so if there is a better way please share.

Just to clarify, this is what I’m looking for in my tableView after parsing the above data:

 Header (Discussions)
   -No rows under this header
 Header (YouTube)
   -Row (Gavin DeGraw - Not Over You)
 Header (Calendar)
   -No rows
 Header (Homework)
   -Row (crashreport)
   -Row (chem notes)
 Header (links)
   -Row (link1)
   -Row (link2)
   -Row (link3)

Thanks for your help. I’ve done so much research on NSDictionary and NSArray methods, but I’m not sure how to fix this problem or code this any other way.

  • 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-28T02:36:32+00:00Added an answer on May 28, 2026 at 2:36 am

    The problem is here:

    for (NSDictionary *myDict in [[response objectAtIndex:section]
    valueForKeyPath:@”item”]) {

    This is fine for the dictionary below, because it loops through an NSArray of NSDictionary objects. So when [myDict allKeys] is called, you are actually calling it on an NSDictionary.

    {
        "@body" = "<p>  homework test</p> ";
        "@class_id" = "";
        "@title" = Homework;
        "@type" = "File Block";
        item =     (
                    {
                "@body" = "https://MYDOMAIN.com/securelink;
                "@title" = "crashreport.rtf";
                "@type" = file;
            },
                    {
                "@body" = "mydomain.com/securelink";
                "@title" = "Chem notes sep 26.docx";
                "@type" = file;
        }
    );
    

    But it is not fine for the next dictionary because you are looping through a dictionary instead of an array, so the for..in loop is looping the keys of the dictionary. Then, you are calling allKeys on an NSString (aka on a key in the dictionary).

    {
        "@body" = "";
        "@class_id" = "";
        "@col" = 1;
        "@title" = YouTube;
        "@type" = "Youtube Block";
        item =     {
            "@body" = "http://www.youtube.com/watch?v=vDWhfsQHq1o&ob=av3e";
            "@title" = "Gavin DeGraw - Not Over You";
            "@type" = link;
        };
    },
    

    You could do something like this instead:

    id item = [[response objectAtIndex:section] valueForKeyPath:@"item"];
    if(item) {
        if([item isKindOfClass:[NSDictionary class]]) {
            NSArray *keys = [(NSDictionary *)item allKeys];
        } else if([item isKindOfClass:[NSArray class]]) {
            for (NSDictionary *myDict in (NSArray *)item) {
                NSArray *keys = [myDict allKeys];
            }
        }
    }
    else {
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.