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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:52:52+00:00 2026-06-08T11:52:52+00:00

My goal is populating a section of a tableview by filling data from all

  • 0

My goal is populating a section of a tableview by filling data from all fetched results on a fetchedResultsController. This is very straighforward and works like a charm.

The second part of my small app is adding a attribute “price” in another section of the same table. It works allright.

This is I’ve used to achieve that:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

        // Return the number of rows in the section.
    if (section == 1) {
        return 1;

    } else return [self.fetchedResultsController.fetchedObjects count];  

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.section == 0) {
    static NSString *ci = @"CellTotal";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:ci];

    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0];
    float expense = 0;
    for (NSManagedObject *object in [sectionInfo objects]) {
        expense += [[object valueForKey:@"precio"] floatValue];
    }


    cell.textLabel.text = [NSString stringWithFormat:@"%f", expense];

    return cell;

} else {
    static NSString *ci = @"Cell";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:ci];
    [self configureCell:cell atIndexPath:indexPath];   
    return cell;
}

}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{

Gastos *g = (Gastos *)[self.fetchedResultsController objectAtIndexPath:indexPath];
cell.detailTextLabel.text = g.nombre;

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
[f setMinimumFractionDigits:2];
[f setMaximumFractionDigits:2];

NSString *precio = [f stringFromNumber: g.precio];

cell.textLabel.text = precio;

}

The problem comes up when I wanted to change the order of the sections in the tableview. If I wanted to show the total addition in section 0, and the list of fetchedresults in section 1, then my app crashes with the error:

Terminating app due to uncaught exception ‘NSRangeException’, reason:
‘* -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]’

Any ideas on what I’m doing wrong? any help is much appreciated, thanks!

update
This is where the code breaks the app:

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{

        Gastos *g = (Gastos *)[self.fetchedResultsController objectAtIndexPath:indexPath];

It look like be working on the first fetched object but fails on the second. I’m really struggling with this question. I’ve been into debugging, checking whether fetch controller exists, etc, and everything seems to be allright and it breaks…
I’m a noob and do not know how to fix the issue 🙁

  • 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-08T11:52:54+00:00Added an answer on June 8, 2026 at 11:52 am

    You have a table view with 2 sections. The second section is populated by a FRC (which has only one section).
    Therefore section 1 in the table view corresponds to section 0 in the FRC.

    Your configureCell:atIndexPath: method is called with the table view’s indexPath (section == 1), but objectAtIndexPath must be called with section == 0. So you must adjust the section number like this:

    - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
    {
        NSIndexPath *frcIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:(indexPath.section - 1)];
        Gastos *g = (Gastos *)[self.fetchedResultsController objectAtIndexPath:frcIndexPath];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal: Retrieve all instance of List<> from interface GameFactory Problem: I retrieve error message
Goal: take results from recognizer stating a name in contacts, then dial their #.
Goal : Add the latest JSON into my project. I download JSON from this
Goal: Having two buttons that should be enable to add or delete data from
Goal: Produce an Excel document with information from 3 associated models that is similar
Goal: Rolling/Running total for all statements at the end of each month. Code: select
Goal: I want to implement a hard-coded lookup table for data that doesn't change
Goal: Extract text from a particular element (e.g. li), while ignoring the various mixed
Goal: Display different context menu if right clicking a row from the listview or
Goal: Display Encapsulate field from Player Problem: Want to display datamember_id , _name and

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.