title: Creating a nib file for a Table View Controller
body: <p>I was trying to follow the <a href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/index.html" rel="nofollow noreferrer">Table View Programming Guide for iPhone OS</a> but was having trouble creating a new Table View Controller that loads its data from a nib file.</p>
  
  <p>Specifically, I was trying to follow the steps in <a href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW6" rel="nofollow noreferrer">this part</a>:</p>
  
  <blockquote>
    <p>If you prefer to load the table view
    managed by a custom table-view
    controller from a nib file, you must
    do the following:</p>
    
    <ol>
    <li>In Interface Builder, create an empty Cocoa Touch nib file (File >
    New).</li>
    <li>Drag a UITableViewController object from the Interface Builder
    Library into the nib document window.</li>
    <li>Save the nib file in your project directory under an appropriate name
    and, when prompted, select your
    project to have the nib file added to
    it.</li>
    <li>Select Table View Controller in the nib document window and open the
    Identity pane of the inspector. Set
    the class to your custom table-view
    controller class.</li>
    <li>Select File’s Owner in the nib document window and set its class
    identity to the custom table-view
    controller class.</li>
    <li>Customize the table view in Interface Builder.</li>
    <li>Select the table-view controller in the nib document window, open the
    Attributes pane of the inspector, and
    enter (or select) the name of the nib
    file in the Nib Name field.</li>
    </ol>
  </blockquote>
  
  <p>So I created a new UITableViewController subclass in Xcode (called "MyTableViewController"), then I went into IB and followed those steps. I made sure to link up all the <strong>Class</strong> attributes to the same name as the UITableViewController subclass I made in Xcode like it says in the steps.</p>
  
  <p>But now I get the following warning in IB: </p>
  
  <blockquote>
    <p>"My Table View Controller" has both its
    "View" and "Nib Name" properties set.
    This configuration is not supported.</p>
  </blockquote>
  
  <p>When I run the application and push the table view controller, it appears but it seems like nothing is being loaded from the nib file at all (e.g. I set the alpha to 0 instead of 1).</p>
  
  <p>Any idea as to what I'm doing wrong?</p>
  
  <p>Thanks for the help.</p>
  
  <hr>
  
  <p>Here's some more information that might help you understand the situation better.</p>
  
  <p>I noticed a few differences between creating a UITableViewController with the template (e.g. by creating a new Navigation-based Application) vs. creating one yourself (e.g. following the steps above). I'm going to refer to each as TemplateNib and CustomNib, respectively, to make it easier to understand the differences.</p>
  
  <p>In TemplateNib, it has the following objects in the document window:</p>
  
  <ul>
  <li>File's Owner</li>
  <li>First Responder</li>
  <li>Table View</li>
  </ul>
  
  <p>In CustomNib, it has the following objects in the document window:</p>
  
  <ul>
  <li>File's Owner</li>
  <li>First Responder</li>
  <li>My Custom Table View Controller
  
  <ul>
  <li>Table View</li>
  </ul></li>
  </ul>
  
  <p>Another difference is in the File's Owner links...</p>
  
  <p>TemplateNib's File's Owner:</p>
  
  <ul>
  <li><strong>Outlets</strong></li>
  <li>tableView -> Table View</li>
  <li>view -> Table View</li>
  <li><strong>Referencing Outlets</strong></li>
  <li>dataSource -> Table View</li>
  <li>delegate -> Table View</li>
  </ul>
  
  <p>CustomNib File's Owner:</p>
  
  <ul>
  <li><strong>Outlets</strong></li>
  <li>view -> (nothing)</li>
  </ul>
  
  <p>CustomNib My Table View Controller:</p>
  
  <ul>
  <li><strong>Outlets</strong></li>
  <li>view -> Table View (this is grayed out so you can't delete it)</li>
  <li><strong>Referencing Outlets</strong></li>
  <li>dataSource -> Table View</li>
  <li>delegate -> Table View</li>
  </ul>
  
  <hr>
  
  <p>Update:</p>
  
  <p>I tried to mimic the .xib file that is created by the template by following these steps:</p>
  
  <ol>
  <li>Created an empty file in Interface Builder.</li>
  <li>Set the File's Owner to the class that inherits from UITableViewController.</li>
  <li>Added a Table View to the document window.</li>
  <li>Set the Table View's dataSource and delegate to File's Owner.</li>
  <li>Set the File's Owner view to the Table View.</li>
  <li>Added a <em>tableView</em> propery in the Identity pane of type <em>UITableView</em>.</li>
  <li>Set the File's Owner tableView property (which I just created) to the Table View.</li>
  </ol>
  
  <p>However, this still seems like it is not loading it from the NIB file. (I also never set the name of the NIB file anywhere though... is there anyplace I need to set it or does it look for one with the same name?).</p>
  
  <p>I then tried overriding initWithNibName to load from the name of the nib file, and now it does seem to load it from the nib file. However, if I look at the .m file of the TemplateNib table view controller, it doesn't need to override this method, why is that? I still think I am doing it the wrong way cause the Programming Guide didn't mention anything about doing it this way.</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>I tried comparing the two .xib files using a diff tool, the only significant difference between the two seems to be:</p>
  
  <pre><code>&lt;string key="superclassName"&gt;UITableViewController&lt;/string&gt;
  // and:
  &lt;reference key="NSSuperview"/&gt;
  </code></pre>
  
  <p>I don't see any reference to the Nib file in the original file anywhere, are there any other files I should check?</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>It seems like the thing that makes TemplateNib load from the nib file is that in the MainWindow.xib (default name given by the template), the RootViewController is added with the NIB Name property having the value "RootViewController". Additionally, its class is set to "RootViewController".</p>
  
  <p>I tried putting a breakpoint in both initWithNibName:bundle: and initWithStyle: on the RootViewController, however, it never gets to there. I'm kinda wondering how the TableViewController is created when you set it up in the MainWindow.xib like that.</p>
  
  <p>I also tried adding the my custom table view controller to MainWindow.xib, setting the class and nib names in hopes that it will load it from the nib file I specified, but it doesn't even call iniWithNibName.</p>