title: UITableViewCell cellForRowAtIndexPath calling large number of rows when first scrolling
body: <p>I have been working on a problem relating to UITableView and cellForRowAtIndexPath.  </p>
  
  <p>I want to give the user the ability to have a very large number of rows much like a large list of email on iPhone. I discovered this problem when I began to create a class that would queue and dequeue groups of records from the database, as needed, in order to conserve memory. I found that when my UITableViewController loads, it then calls cellForRowAtIndexPath for the typical first 10 indexes (0 through 9).  The problem ocurrs when I either click my mouse on the simulator's black outer surface area or I attempt to scroll down on the UITableView using an upward gesture.  At this point, cellForRowAtIndexPath gets called for all remaining indexes.  This happens even if there are 1000+ cells.  I have attempted recreating a VERY SIMPLE project with only 100 indexes (nothing fancy).  It does exactly the same thing.. as soon as I scroll, it calls cellForRowAtIndexPath from positions 10 to 99. </p>
  
  <p>Is this the normal behavior of a UITableView?  Does anyone anyone have any ideas why it is inefficiently calling all rows?</p>
  
  <p>I will say that once this initial pass occurs, it seems like it begins to work correctly.  I am really puzzled by this because it makes it almost impossible to create a class for queuing and de-queuing records as need.  </p>
  
  <p>Here is the code on my much simpler sample project:</p>
  
  <pre><code>// Customize the number of sections in the table view.
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 1;
  }
  
  
  // Customize the number of rows in the table view.
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return 100;
  }
  
  
  // Customize the appearance of table view cells.
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  
   printf("RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = %d\n", indexPath.row);
  
  
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      }
  
   cell.textLabel.text = @"Example Text";
  
   return cell;  
  }
  </code></pre>
  
  <p>Console:</p>
  
  <p>......
  Initial Load of View
  ......</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 0</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 1</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 2</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 3</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 4</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 5</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 6</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 7</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 8</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 9</p>
  
  <p>......
  First Scroll Gesture
  ......</p>
  
  <p>ootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 11</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 12</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 13</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 14</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 15</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 16</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 17</p>
  
  <p>.
  .
  I removed a few here to shorten it up
  .
  .</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 97</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 98</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 99</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 10</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 11</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 12</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 13</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 14</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 15</p>
  
  <p>RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = 16</p>
  
  <p>(gdb) </p>
  
  <p>Thanks for your help.</p>
  
  <p>Eric</p>
  
  <p><strong>Edit (subsequent day) --> Today I thought to try a real device instead of my simulator.  My iPhone 3GS does not reproduce this strange behavior.  I believe there might be something wrong with the simulator on my machine.  I plan to try another MAC when time permits.</strong></p>