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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:48:16+00:00 2026-05-15T19:48:16+00:00

I am having a problem with my code skipping over the if(cell == nil)

  • 0

I am having a problem with my code skipping over the if(cell == nil) after about nine trips through the cellForRowAtIndexPath. Then items in my table start repeating and do so every nine items. When I remove the if(cell == nil) line, the table comes out beautifully, with all the data in the right order. However, if I scroll to the bottom of the table, my app crashes so that is not a good solution. Any ideas please??

Thank you!

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];     


    NSString *temp = [[views objectAtIndex:indexPath.row] objectForKey:@"racer"];
    NSString *val = [[views objectAtIndex:indexPath.row] objectForKey:@"pointsScored"];

    // Set up the cell...
    cell.textLabel.text = temp;
    cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
    cell.detailTextLabel.text = val;

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    [temp release];
    [val release];

    }

    return cell;
}
  • 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-15T19:48:17+00:00Added an answer on May 15, 2026 at 7:48 pm

    KLevSki,

    That is because you are re-using tableview cells via dequeueReusableCellWithIdentifier which is a good thing on the iPhone platform. What happens is this:

    1) Cell is created in the if (cell==nil) section

    2) Once a number of cells are created (in your case 9 of them, based roughly on how many are shown on screen), the OS begins to re-use the table cells to be a good memory manager instead of creating a unique table cell for each and every row which could be memory intensive

    3) Since the cell is being re-used, all you need to do in the section after the if (cell==nil) block is to update/change the information on each cell.

    As an example… If you created a cell that had only an icon and a label on it, each time the cell is scrolled into view, you would update the icon and label to whatever image/string is appropriate for that cell.

    For your case:

    ...
    
    if (cell == nil) {
    
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];     
    
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    }
    
    // update cell
    cell.textLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@"racer"];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
    cell.detailTextLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@"pointsScored"];
    
    return cell;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i'm having a problem with this code. my problem is that the first
I'm having a problem with this code: #include <iostream> using namespace std; class A
I'm having a problem with some code I've written. I've had to anonymize it,
I'm having a problem with some code that used to work in PHP 4.X
I am having problem getting this piece of code to run. The class is
I am having a problem getting this code to work. Basically I Go from
I'm having problem with datagrid view. I have attached an image with the code
I am having problem with drawing multiple lines during repaint. The code is as
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
Having a problem with the dataGridView control being populated with Display members: Code: private

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.