<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iphone.mitchallen.com &#187; UITableViewController</title>
	<atom:link href="http://mitchallen.com/iphone/archives/tag/uitableviewcontroller/feed" rel="self" type="application/rss+xml" />
	<link>http://mitchallen.com/iphone</link>
	<description>random notes on iPhone development</description>
	<lastBuildDate>Tue, 10 Aug 2010 20:36:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Changing the display size of a UITableView</title>
		<link>http://mitchallen.com/iphone/archives/184</link>
		<comments>http://mitchallen.com/iphone/archives/184#comments</comments>
		<pubDate>Tue, 26 May 2009 21:11:27 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[UITableViewController]]></category>
		<category><![CDATA[UIViewController]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=184</guid>
		<description><![CDATA[UPDATE 29-Apr-2010: By popular demand, here is a git repository with an updated sample: git clone git@github.com:mitchallen/TableSize2.git Note that I have NOT updated the code in this post. Look at the repository for the new code. This new sample fixes two issues: missing IBOutlet and the deprecated setText method on the cell. To see how [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE 29-Apr-2010:</strong></p>
<p>By popular demand, here is a git repository with an updated sample:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git@github.com:mitchallen/TableSize2.git</pre></div></div>

<p>Note that I have NOT updated the code in this post.  Look at the repository for the new code.  This new sample fixes two issues:  missing IBOutlet and the deprecated setText method on the cell.</p>
<p>To see how it looks in &#8220;boxed&#8221; mode on the iPad, set the compiler to: Simulator &#8211; 3.2 | Debug.</p>
<p><a href="http://mitchallen.com/iphone/wp-content/uploads/2009/05/Screen-shot-2010-04-29-at-10.36.44-PM.png"><img class="alignnone size-medium wp-image-547" title="Screen shot 2010-04-29 at 10.36.44 PM" src="http://mitchallen.com/iphone/wp-content/uploads/2009/05/Screen-shot-2010-04-29-at-10.36.44-PM-231x300.png" alt="" width="231" height="300" /></a></p>
<hr size="1" /><strong>ORIGINAL POST</strong></p>
<p>Here is an example of how to create a view that contains a <strong>UITableView</strong> that doesn&#8217;t take over the whole screen.  An example of an application that uses a small table is the <strong>Stocks</strong> application that comes with the iPhone / iPod Touch.  You may think you need a <strong>UITableViewController</strong> &#8211; but that only gets in the way and takes over the view.</p>
<ul>
<li>Create a View-based iPhone application and call it <strong><em>TableSize1</em></strong></li>
<li>Modify <strong><em>TableSize1ViewController.h</em></strong> so that it looks like this:</li>
</ul>
<p><strong>TableSize1ViewController.h</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1ViewController.h</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 5/26/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #a61390;">@interface</span> TableSize1ViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
&nbsp;
	UITableView <span style="color: #002200;">*</span>tableView;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>retain, nonatomic<span style="color: #002200;">&#41;</span> UITableView <span style="color: #002200;">*</span>tableView;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<ul>
<li>Modify <strong><em>TableSize1ViewController.m</em></strong> so that it looks like this:</li>
</ul>
<p><strong>TableSize1ViewController.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1ViewController.m</span>
<span style="color: #11740a; font-style: italic;">//  TableSize1</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 5/26/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TableSize1ViewController.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TableSize1ViewController
&nbsp;
<span style="color: #a61390;">@synthesize</span> tableView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">1</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">20</span>;  <span style="color: #11740a; font-style: italic;">// Test hack to display multiple rows.</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectZero reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>szCell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithFormat<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Row %i&quot;</span>, indexPath.row <span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>cell setText<span style="color: #002200;">:</span>szCell<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>szCell release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Set up the cell</span>
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Navigation logic -- create and push a new view controller</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>didReceiveMemoryWarning <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super didReceiveMemoryWarning<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// Releases the view if it doesn't have a superview</span>
    <span style="color: #11740a; font-style: italic;">// Release anything that's not essential, such as cached data</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<ul>
<li>In the <strong>Resources</strong> folder, double-click <strong>TableSize1ViewController.xib</strong> to launch <strong>Interface Builder</strong></li>
<li>From <strong>Library / Cocoa Touch Plugin / Data Views</strong> drag a <strong>Table View</strong> on to the <strong>View</strong> and make it about half the height of the view (Select <strong>Tools / Library</strong> from the main menu if it isn&#8217;t visible)</li>
<li>Click on the new <strong>Table View</strong></li>
<li>Click on the second tab in the <strong>Inspector</strong> window (Select <strong>Tools / Inspector</strong> from the main menu if it isn&#8217;t visible)</li>
<li>After clicking the second tab, the title of the <strong>Inspector</strong> window should be <strong>Table View Connections</strong></li>
<li>Under <strong>Outlets</strong>: for both <strong>dataSource</strong> and <strong>delegate</strong>, drag the mouse from the circles next to them to the <strong>File&#8217;s Owner</strong> icon in the <strong>TableSize1ViewController.xib</strong> window.</li>
<li>Under <strong>Referencing Outlets</strong>: drag from <strong>New Referencing Outlet</strong> to the <strong>File&#8217;s Owner</strong> icon and select <strong>tableView</strong>.</li>
<li>With <strong>Interface Builder</strong> in focus, select <strong>File / Save</strong></li>
<li>Go back to your project window and click <strong>Build and Go</strong></li>
<li>Your application should now display a table that only takes up half the screen.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/184/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Adding Headers and Footers to Table Views</title>
		<link>http://mitchallen.com/iphone/archives/172</link>
		<comments>http://mitchallen.com/iphone/archives/172#comments</comments>
		<pubDate>Mon, 25 May 2009 23:15:47 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[footers]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[UITableViewController]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=172</guid>
		<description><![CDATA[Here is an easy way to create headers and footers for iPhone Table Views. In your Xcode project right-click on the Resources folder Select: Add / New File &#8230; / iPhone OS / User Interfaces / View XIB / [Next] Call it HeaderView.xib and click Finish GIve the View a unique background color and set [...]]]></description>
			<content:encoded><![CDATA[<p>Here is an easy way to create headers and footers for iPhone Table Views.</p>
<ol>
<li>In your Xcode project right-click on the <strong>Resources</strong> folder</li>
<li>Select: <strong>Add / New File &#8230; / iPhone OS / User Interfaces / View XIB / [Next]</strong></li>
<li>Call it <strong><em>HeaderView.xib</em></strong> and click <strong>Finish</strong></li>
<li>GIve the View a unique background color and set the height to 44</li>
<li>Repeat for <strong>FooterView.xib</strong></li>
<li>Save both files</li>
</ol>
<p>In your <strong>UITableViewController</strong> class modify <strong>viewDidLoad</strong> to contain the following (the editing = YES line is optional &#8211; just showing you how to display those cool delete widgets):</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
&nbsp;
	self.tableView.editing <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;	<span style="color: #11740a; font-style: italic;">// Enable delete buttons.</span>
&nbsp;
	UIView <span style="color: #002200;">*</span>hView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> loadNibNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;HeaderView&quot;</span> owner<span style="color: #002200;">:</span>self options<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	self.tableView.tableHeaderView <span style="color: #002200;">=</span> hView;
&nbsp;
	UIView <span style="color: #002200;">*</span>fView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> loadNibNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FooterView&quot;</span> owner<span style="color: #002200;">:</span>self options<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	self.tableView.tableFooterView <span style="color: #002200;">=</span> fView;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>As far as I can tell you can&#8217;t lock the header and footer in place.  That will require a custom table view.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/172/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
