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

  • Home
  • SEARCH
  • 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 7919193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:46:58+00:00 2026-06-03T15:46:58+00:00

If I have a UITableView that has 4 rows in it then shouldn’t the

  • 0

If I have a UITableView that has 4 rows in it then shouldn’t the cellForRowAtIndexPath method be called 4 times when I navigate to that view? I am finding that it is being called multiple times e.g. if there are 4 rows it is called 8 times when I drill down into the UITable view and then 12 times when I navigate back up to the same UITableView.

Am I just misunderstanding how this method works? I thought it should be called once for each row that is displayed (there is no scrolling involved as the contents of the table view easily fits on my iPad screen).

I should probably note that the UITableView is contained in the MasterViewController of a UISplitViewController on an iPad.

EDIT: The real problem I am getting is inconsistency in the way that the following code is being applied:

if (selectedNavItem.folder.isAssignedToUser != [NSNumber numberWithInt:1]) 
        {
            NSLog(@"%@", cell.textLabel.text);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.userInteractionEnabled = NO;
            cell.textLabel.enabled = NO;
            cell.detailTextLabel.text = @"Access not granted";
            cell.detailTextLabel.enabled = NO;
        }

When I first “drill down” to a particular level of my navigation stack things work as they should. But later if I navigate back up or down then I find that various rows get treated incorrectly i.e. they end up disabled when they should be enabled. That led me to put a break point in and some logging code to try to find out what was going on. I found that the code above was being called more times than there was rows – and the cell.textLabel.text value that I was logging did not make sense – a value for the same row was being logged multiple times – and other rows were not being logged at all.

EDIT: Providing some code as requested:

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

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


- (NSFetchedResultsController *)fetchedResultsController
{
    if (__fetchedResultsController != nil) {
        return __fetchedResultsController;
    }

    // Set up the fetched results controller.
    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"NavItem" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort keys as appropriate.
    NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
    NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
    NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.
        managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return __fetchedResultsController;
}   

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NavItem *selectedNavItem = (NavItem *)managedObject;
    cell.textLabel.text = [[managedObject valueForKey:@"name"] description];
    cell.detailTextLabel.text = @"";

    if (selectedNavItem.folder != nil) {
        cell.imageView.image = [UIImage imageNamed:@"Folder.png"];


        //NSLog(@"%@", selectedNavItem.folder.isAssignedToUser);

        if (selectedNavItem.folder.isAssignedToUser != [NSNumber numberWithInt:1]) 
        {
            NSLog(@"%@", cell.textLabel.text);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.userInteractionEnabled = NO;
            cell.textLabel.enabled = NO;
            cell.detailTextLabel.text = @"Access not granted";
            cell.detailTextLabel.enabled = NO;
        }
    }
    else if (selectedNavItem.document != nil) {
        cell.detailTextLabel.text  = [[selectedNavItem.document valueForKey:@"itemDescription"] description];

        if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"pdf"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"pdf.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"doc"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"docx"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"Word-32x32.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"xls"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"xlsx"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"Excel-32x32.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"ppt"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"pps"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"Powerpoint-32x32.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"mp3"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"wav"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"65-note.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"mp4"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"mov"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"46-movie-2.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"ibooks"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"ibooks-icon.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"png"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"bmp"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"jpg"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"jpeg"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"tif"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"tiff"] || [[selectedNavItem.document.fileName pathExtension] isEqualToString:@"gif"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"41-picture-frame.png"];
        }
        else 
        {
            cell.imageView.image = [UIImage imageNamed:@"179-notepad.png"];
        }


    }
    else if (selectedNavItem.attachment != nil) {
        cell.detailTextLabel.text  = [[selectedNavItem.attachment valueForKey:@"itemDescription"] description];

        if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"pdf"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"pdf.png"];
        }
        else if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"doc"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"docx"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"Word-32x32.png"];
        }
        else if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"xls"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"xlsx"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"Excel-32x32.png"];
        }
        else if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"ppt"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"pps"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"Powerpoint-32x32.png"];
        }
        else if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"mp3"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"65-note.png"];
        }
        else if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"mp4"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"46-movie-2.png"];
        }
        else if ([[selectedNavItem.document.fileName pathExtension] isEqualToString:@"ibooks"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"ibooks-icon.png"];
        }
        else if ([[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"png"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"bmp"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"jpg"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"jpeg"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"tif"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"tiff"] || [[selectedNavItem.attachment.fileName pathExtension] isEqualToString:@"gif"]) 
        {
            cell.imageView.image = [UIImage imageNamed:@"41-picture-frame.png"];
        }
        else 
        {
            cell.imageView.image = [UIImage imageNamed:@"179-notepad.png"];
        }
    }

}
  • 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-03T15:47:01+00:00Added an answer on June 3, 2026 at 3:47 pm

    The method is called when the cell appears, so whenever a cell appears, the method is called. Also, the cells are reused. So even if the method for a particular cell is called once, it maybe called for another time when this cell disappears and then appears again.

    • 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 has five sections. Just as the title describes cellForRowAtIndexPath
I have a very simple UITableView that has 3 sections, and 3 rows per
Is it possible to have a UITableView that has a fixed height for all
I have a custom UITableView cell that has a UIImageView sized to the width
I have a UITableView that I am allocating multiple times during the lifetime of
I have a UITableView that displays various nsstrings from a custom object called a
I have a UITableView that is grouped into sections and has a number of
I have a regular-style UITableView—the one that has a white background and gray horizontal
I am working on a project that has a uitableview with 3 rows in
I have a UITableView with many rows that push a DetailViewController depending on 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.