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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:14:07+00:00 2026-06-13T17:14:07+00:00

I have a tableview that is filled up with dates. My section header is

  • 0

I have a tableview that is filled up with dates. My section header is the month name. You can see my tableview over here.

What I want is that it scrolls to the section of the month of that moment. For setting my section headers I use this method.

 id <NSFetchedResultsSectionInfo> theSection = [[self.fetchedResultsController sections] objectAtIndex:section];

        static NSArray *monthSymbols = nil;
        NSArray *dutchMonths = [[NSArray alloc]initWithObjects:@"Januari",@"Februari",@"Maart",@"April",@"Mei",@"Juni",@"Juli",@"Augustus",@"September",@"Oktober",@"November",@"December", nil];
        if (!monthSymbols) {
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setCalendar:[NSCalendar currentCalendar]];
            [formatter setMonthSymbols:dutchMonths];
            monthSymbols = [formatter monthSymbols];

        }
        NSLog(@"%@",monthSymbols);
        NSInteger numericSection = [[theSection name] integerValue];

        NSInteger year = numericSection / 1000;
        NSInteger month = numericSection - (year * 1000);

        NSString *titleString = [NSString stringWithFormat:@"%@", [monthSymbols objectAtIndex:month-1]];
        label.text = titleString;

I know already that I have to use this method.

[sampleListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

But how do I get the indexpath of the correct row?

Any help? If you need more details. Please help.

Kind regards.

  • 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-13T17:14:09+00:00Added an answer on June 13, 2026 at 5:14 pm

    Looks like you can get an index by looping through your sections array (from self.fetchedResultsController) and comparing the month obtained from the object in question to the month from the current date. If you have a match, then your indexPath would be:

    NSIndexPath *path = [NSIndexath indexPathForRow:0 inSection:foundIndex];
    

    You should also make the dutchMonths array static so it isn’t created every time that method is called. Also, if you aren’t using ARC, it’s leaking (unless the release code is not posted). A general rule of thumb is to make the date formatter static too, or manage one instance of it in some way, because it is an expensive operation. I know with this code it is only created once since you only use it to populate the monthSymbols array, but if you need to use the same formatter in other code, then you’ll want to rewrite that.

    To do all of this, you should extract the logic in this method and put it in smaller, reusable methods like

    - (NSInteger)monthFromSection:(id<NSFetchedResultsSectionInfo>)section;
    

    Then you can write:

    NSIndexPath *path = nil;
    NSInteger currentMonth = // Calculate month from date returned by [NSDate date]
    NSArray *sections = [self.fetchedResultsController sections];
    for (int i = 0; i < sections.count; i++)
    {
        if (currentMonth = [self monthFromSection:[sections objectAtIndex:i]])
        {
            path = [NSIndexPath indexPathForRow:0 inSection:i];
            break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a tableView with 3 cells. i want to change .detailTextLabel of that
I have a tableview that is blank by default. User can add cells to
I have a tableView that I want to allow editing and delete rows. I
I have a TableView that has a section that is clickable. Under that section
I have a tableview that fill with custom cells,, Now I want to increase
Suppose you have a tableview that you can refresh. Would you keep the activityAnimator
Here is my predicament: I have a tableview controller that loads a detail view
I have a tableView that present a list of Books, each of the table
I have a tableView that's loosely based on the DetailViewController in ye olde SQLiteBooks.
I have a tableview that occupies only the bottom third of my view. 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.