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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:41:30+00:00 2026-05-25T19:41:30+00:00

Im stuck with this problem, I have a UITableView and i populate it with

  • 0

Im stuck with this problem, I have a UITableView and i populate it with data from an NSMutableArray. The Array has the following structure:

<array>
<dict>
    <key>Date</key>
    <string>2011.18.09 04:17 PM</string>
    <key>Value</key>
    <string>58.00</string>
</dict>
<dict>
    <string>2011.15.09 04:21 PM</string>
    <key>Value</key>
    <string>0.00</string>
</dict>
</array>

I would like to have a section for each day in the Array. I already figured out how to return the number of dates, and name the section headers, the only problem i am having is returning the number of rows per section and then defining the cells for each row.

Working code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedData.daf"];
NSMutableArray *d = [NSMutableArray arrayWithContentsOfFile:path];
NSMutableArray *test = [d valueForKey:@"Date"];
NSString *g = [[NSString alloc] init];
NSString *s = [[NSString alloc] init];
c = 0;
    for (g in test) {
        s = [g substringToIndex:[g length]-9];
        if (![s isEqualToString:sf]) {
            c = c+1;
            [dates addObject:s];
        }
        sf = [g substringToIndex:[g length]-9];
    }
return c;

that code counts the different dates and creates an array with the section names. Could anybody help me with defining the number of rows (by counting the number of objects for each day) and by giving the rows the right value in the ´cellForRowAtIndexPath´ method.

  • 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-25T19:41:31+00:00Added an answer on May 25, 2026 at 7:41 pm

    Ok, i finally found a solution. It is actually pretty easy to understand. To return the numbers of sections, i need to find out how many different dates there are in the array. For the number of rows i need to know how many values there are for each day. so here is what i did:

    Rows:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        // Return the number of rows in the section.
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedData.daf"];
        NSMutableArray *d = [[NSMutableArray alloc] initWithContentsOfFile:path];
        NSArray *jes = [[NSArray alloc] init];
        count = [[NSMutableArray alloc] init];
        NSString *before = [[NSString alloc] init];
        NSString *after = [[NSString alloc] init];
        jes = [d valueForKey:@"Date"];
        int ja = -1;
        for (int i = 1; i<=[jes count];i++) {
            ja = ja+1;
            before = [jes objectAtIndex:ja];
            if (![before isEqualToString:after]) {
                NSCountedSet *ca = [[NSCountedSet alloc] initWithArray:jes];
                int f = [ca countForObject:before];
                [count addObject:[NSString stringWithFormat:@"%i",f]];
            }
            after = before;
        }
        return [[count objectAtIndex:section] intValue];
    }
    

    Sections:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedData.daf"];
        NSMutableArray *d = [[NSMutableArray alloc] initWithContentsOfFile:path];
        NSArray *jes = [[NSArray alloc] init];
        count = [[NSMutableArray alloc] init];
        NSString *before = [[NSString alloc] init];
        NSString *after = [[NSString alloc] init];
        jes = [d valueForKey:@"Date"];
        int ja = -1;
        for (int i = 1; i<=[jes count];i++) {
            ja = ja+1;
            before = [jes objectAtIndex:ja];
            if (![before isEqualToString:after]) {
                NSCountedSet *ca = [[NSCountedSet alloc] initWithArray:jes];
                int f = [ca countForObject:before];
                [count addObject:[NSString stringWithFormat:@"%i",f]];
            }
            after = before;
        }
        return [count count];
    }
    

    Titles:

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedData.daf"];
        NSMutableArray *d = [NSMutableArray arrayWithContentsOfFile:path];
        NSMutableArray *test = [d valueForKey:@"Date"];
        NSString *g = [[NSString alloc] init];
        NSString *s = [[NSString alloc] init];
        NSString *sf = [[NSString alloc] init];
        dates = [[NSMutableArray alloc] init];
        c = 0;
        for (g in test) {
            s = [g substringToIndex:[g length]-9];
            if (![s isEqualToString:sf]) {
                c = c+1;
                [dates addObject:s];
            }
            sf = [g substringToIndex:[g length]-9];
        }
        return [dates objectAtIndex:section];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope to get solution to this problem. I have been stuck on it since
I have a UITableView on a view. This UITableView has cells which are made
I'm stuck with this problem I have a serie of pages of the CharacterView
I have been stuck with this problem for a while now, and I just
I'm kind of stuck with this problem. I have a UIImageView animation with 37
I am stuck in a problem, I have a uitableview with rows let say
I have been really stuck on this problem. My validation for my model fails
I'm new to android and have been stuck on this problem for a long
I have just started developing iphone applications, but now i'm stuck with this problem,
I have been stuck on this problem for almost 2 days now, consider the

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.