title: UITableView scrolling crashes App
body: <p><strong>Preface</strong>: I am new to the iPhone SDK, Obj-C, Interface Builder and Cocoa. I'm likely doing something obviously wrong.</p>
  
  <p><strong>Question</strong>:
  I have a <code>UITableView</code> which crashes if I scroll it.  It will scroll a little to reveal the full cell of the bottom most half-hidden cell, but won't load the next one.  Similarly, if I scroll past the top to fully hide the bottom most cell, and it rubber bands back to show that cell, it will crash before showing it.  This strikes me as odd because it is drawing the first 7 of 11 cells correctly. The cell data is in an <code>NSArray</code>, in a <code>UITableViewController</code> linked as both the <code>dataSource</code> and <code>delegate</code> for the <code>UITableView</code> in Interface Builder. It works when the view initializes.</p>
  
  <p>I'm making an App I thought I'd be done with 2 days ago that just calculates combinations and displays a list of them in what I thought would be a convenient scrolling table view.  Right now, it doesn't even calculate everything, the <code>NSArray</code> in the <code>DataSource</code> is initialized once with some strings like <code>@"Hello"</code> and <code>@"World"</code>.</p>
  
  <p><strong>Steps to reproduce</strong>:
  Because I'm using IB, I can't exactly show you the full story in code. So I'm going to describe what I did so far and hope it doesn't make you sleepy.</p>
  
  <p>Made a new "Tab Bar Application" in Xcode, because I want 2 tabs, and I don't want a nav bar nor a full screen table. I moved the <code>MainWindow.xib</code>'s first tab view out into <code>FirstView.xib</code> as an analogue to the given <code>SecondView.xib</code>. This worked nicely. I modified the view to contain two <code>UITextField</code>s for inputs, and a <code>UITableView</code> for output. This worked but the table was empty. I subclassed the <code>UITableViewController</code> wherein I populated an <code>NSArray</code> property named <code>combinations</code> with 11 strings, and then added</p>
  
  <pre><code>// Set up the cell...
  cell.userInteractionEnabled = NO;
  cell.text = [combinations objectAtIndex:indexPath.row];
  </code></pre>
  
  <p>where there had only been the comment.  In IB I added a <code>Table View Controller</code> to the <code>FirstView.xib</code> and set it's class name to match the name of this new subclass, and control-dragged the <code>Table View</code> in my view onto this <code>Combinations Table View Controller</code> twice. Once linking the <code>dataSource</code> and once the <code>delegate</code>. Although I get the same behavior if only the <code>dataSource</code> is linked.</p>
  
  <p>This runs and populates the table's visible rows (6.5) with the first 7 values in the <code>dataSource</code> <code>combinations</code>. I <em>can</em> scroll 0.5 cells down, and then back up. But if I scroll more than 0.5 cells up or down the app will crash. The explanation in the report reads:</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
  reason: '*** -[NSCFTimer tableView:cellForRowAtIndexPath:]:
  unrecognized selector sent to instance 0x52ca40'
  </code></pre>
  
  <p>I didn't make an <code>NSCFTimer</code> nor did I link it to my <code>Table View</code>, I suspect that the <code>cellForRowAtIndexPath</code> is exactly a message that should have gone to my <code>dataSource</code> or <code>delegate</code> so I'm confused at why it went astray and where it ended up going.</p>
  
  <p><strong>Update</strong>: Thanks for the answers and comments. My problem seems to be that the <code>CombinationsTableViewController</code> (subclass of <code>UITableViewController</code>) is actually not instantiated any particular place in my code. It does get created as some time (when the <code>FirstView.xib</code> is loaded) and is apparently managed while the initial tableView is filled with 7 cells, and is then released. So I need to identify where/how to make a retained reference to this controller. My <code>Application Delegate</code> should probably have some outlet that holds this controller that can be linked as the instance which is in the <code>xib</code>. Yeah, I'm new to this. I know I could just eliminate these troubles by avoiding the IB and doing things explicitly in code, but I figure I want to learn to use the IB flexibly.</p>
  
  <p><strong>Finally</strong>: Yes, I needed a retained instance of the table view controller. It sounds elementary, but this wasn't clear when working with the IB as I had. Read my own post for the whole process and fix.</p>
  
  <p><strong>Aside</strong>: Either the debugger needs detailed instructions (any links appreciated), or it doesn't work very well. I seem to get more information more quickly by letting the App crash and reading the report it generates. But this requires a tedious termination, relaunch, and 3 clicks. I had really wanted to move on from this to wiring up the inputs, doing the calculation, and updating the table with each change. That's supposed to be the hard part, not this making a framework member work stuff.</p>
  
  <p><strong>Further rambling</strong>: This was all in the iPhone SDK for 2.2.1. At the time iPhone OS 3.0 non-beta was not available yet without joining the club for cold hard cash. I expected it to be at the open of WWDC 2009, but it was actually today (July 17th 2009) that the free public 3.0 SDK was made available.</p>