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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:59:50+00:00 2026-06-06T07:59:50+00:00

I have a UITableView that is being populated by core data. Now, when I

  • 0

I have a UITableView that is being populated by core data. Now, when I click on a cell, it pushes me to another view where I can edit the data that is in that particular index, when I return, the system either crashes or else doesn’t load the changes onto the labels, any ideas? code below

-(void)viewWillAppear:(BOOL)animated 
{    
    searchCriteria = [[NSMutableString alloc] initWithString:@"clientName"];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientName" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];    
    fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];

    [self.clientTableView reloadData];
    [super viewWillAppear:animated];    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath];
    clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)];
    clientNameLabel.tag = 1;
    clientNameLabel.backgroundColor = [UIColor clearColor];
    clientNameLabel.textColor = [UIColor whiteColor];
    clientNameLabel.font =  [UIFont boldSystemFontOfSize:13];
    clientNameLabel.text = client.clientName;
    [cell.contentView addSubview:clientNameLabel];

    clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)];
    clientAccountNumberLabel.tag = 2;
    clientAccountNumberLabel.textColor = [UIColor whiteColor];
    clientAccountNumberLabel.backgroundColor = [UIColor clearColor];
    clientAccountNumberLabel.font =  [UIFont boldSystemFontOfSize:13];
    clientAccountNumberLabel.text = client.clientAccountNumber;
    [cell.contentView addSubview:clientAccountNumberLabel];

    clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)];
    clientTelephoneNumberLabel.tag = 3;
    clientTelephoneNumberLabel.textColor = [UIColor whiteColor];
    clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor];
    clientTelephoneNumberLabel.font =  [UIFont boldSystemFontOfSize:13];
    [cell.contentView addSubview:clientTelephoneNumberLabel];

    addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
    addressLine1Label.tag = 4;
    addressLine1Label.textColor = [UIColor whiteColor];
    addressLine1Label.backgroundColor = [UIColor clearColor];
    addressLine1Label.font =  [UIFont boldSystemFontOfSize:13];
    addressLine1Label.text = client.addressLine1;
    [cell.contentView addSubview:addressLine1Label];

    addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
    addressLine2Label.tag = 5;
    addressLine2Label.textColor = [UIColor whiteColor];
    addressLine2Label.backgroundColor = [UIColor clearColor];
    addressLine2Label.text = client.addressLine2;
    addressLine2Label.font =  [UIFont boldSystemFontOfSize:13];
    [cell.contentView addSubview:addressLine2Label];

    addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
    addressLine3Label.tag = 6;
    addressLine3Label.textColor = [UIColor whiteColor];
    addressLine3Label.backgroundColor = [UIColor clearColor];
    addressLine3Label.font =  [UIFont boldSystemFontOfSize:13];
    addressLine3Label.text = client.addressLine3;
    [cell.contentView addSubview:addressLine3Label];

    addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
    addressLine4Label.tag = 7;
    addressLine4Label.textColor = [UIColor whiteColor];
    addressLine4Label.backgroundColor = [UIColor clearColor];
    addressLine4Label.font =  [UIFont boldSystemFontOfSize:13];
    addressLine4Label.text = client.addressLine4;
    [cell.contentView addSubview:addressLine4Label];

    return cell;
}

The Crash Logs are as follows:

2012-06-23 17:08:05.541 iSalesForce[11773:15803] no object at index 1 in section at index 0

And some other code you might find useful are:

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [fetchedObjects count];
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70.0;
}
  • 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-06T07:59:52+00:00Added an answer on June 6, 2026 at 7:59 am

    The problem is most likely in the fact your fetchedResultsController has gone stale (are you using ARC? is that fetchedResultsController a “strong” property?

    Or it may simply be that your fetchedResultsController has no objects and you’re insisting that you have exactly one object in your “numberOfSectionsInTableView” method, regardless of the true contents of “fetchedResultsController“.

    Try this new & improved function:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
        if(cell == nil)
        {
            // this should never happen, but just in case...
            NSLog( @"cell is still - unexpectedly - nil" );
        } else {
            if(self.fetchedResultsController == nil)
            {
                NSLog( @"surprise, fetchedResultsController is nil" );
            } else {
                Client * client = nil;
                @try {
                    client = [self.fetchedResultsController objectAtIndexPath:indexPath];
                }
                @catch (NSException * e) {
                    NSLog( @"exception thrown while trying to fetch something from fetchedResultsController - %@ %@", [e name], [e reason] );
                }
                @finally {
                    clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)];
                    clientNameLabel.tag = 1;
                    clientNameLabel.backgroundColor = [UIColor clearColor];
                    clientNameLabel.textColor = [UIColor whiteColor];
                    clientNameLabel.font =  [UIFont boldSystemFontOfSize:13];
                    clientNameLabel.text = client.clientName;
                    [cell.contentView addSubview:clientNameLabel];
    
                    clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)];
                    clientAccountNumberLabel.tag = 2;
                    clientAccountNumberLabel.textColor = [UIColor whiteColor];
                    clientAccountNumberLabel.backgroundColor = [UIColor clearColor];
                    clientAccountNumberLabel.font =  [UIFont boldSystemFontOfSize:13];
                    clientAccountNumberLabel.text = client.clientAccountNumber;
                    [cell.contentView addSubview:clientAccountNumberLabel];
    
                    clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)];
                    clientTelephoneNumberLabel.tag = 3;
                    clientTelephoneNumberLabel.textColor = [UIColor whiteColor];
                    clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor];
                    clientTelephoneNumberLabel.font =  [UIFont boldSystemFontOfSize:13];
                    [cell.contentView addSubview:clientTelephoneNumberLabel];
    
                    addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
                    addressLine1Label.tag = 4;
                    addressLine1Label.textColor = [UIColor whiteColor];
                    addressLine1Label.backgroundColor = [UIColor clearColor];
                    addressLine1Label.font =  [UIFont boldSystemFontOfSize:13];
                    addressLine1Label.text = client.addressLine1;
                    [cell.contentView addSubview:addressLine1Label];
    
                    addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
                    addressLine2Label.tag = 5;
                    addressLine2Label.textColor = [UIColor whiteColor];
                    addressLine2Label.backgroundColor = [UIColor clearColor];
                    addressLine2Label.text = client.addressLine2;
                    addressLine2Label.font =  [UIFont boldSystemFontOfSize:13];
                    [cell.contentView addSubview:addressLine2Label];
    
                    addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
                    addressLine3Label.tag = 6;
                    addressLine3Label.textColor = [UIColor whiteColor];
                    addressLine3Label.backgroundColor = [UIColor clearColor];
                    addressLine3Label.font =  [UIFont boldSystemFontOfSize:13];
                    addressLine3Label.text = client.addressLine3;
                    [cell.contentView addSubview:addressLine3Label];
    
                    addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
                    addressLine4Label.tag = 7;
                    addressLine4Label.textColor = [UIColor whiteColor];
                    addressLine4Label.backgroundColor = [UIColor clearColor];
                    addressLine4Label.font =  [UIFont boldSystemFontOfSize:13];
                    addressLine4Label.text = client.addressLine4;
                    [cell.contentView addSubview:addressLine4Label];
    
                }
    
                Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath];
            }
        }
        return cell;
    }
    

    (I didn’t actually test this out… but I did put some new error checking and exception handling into it for you)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView that is populated with cells by core data and an
I have UITableView that contains many cell. User can expand cell to see more
I have a view controller that lists some data in an UITableView . To
I have a UITableView that is being populated from an NSMutable array that has
I have a UItableView that segues to a different view controller. I'm using a
I have a UITableView that displays single large images in each cell. The names
I have a uitableview that loads fairly large images in each cell and the
I have a UITableView that was created from data coming from a mutable array.
I have a UITableView of UITableViewCells that so far performed well. I now aded
In my iPhone app I have a UIViewController that has a UITableView and another

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.