<?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>Progressive Degradation &#187; Building Your App</title>
	<atom:link href="http://walterg2.com/tag/building-your-app/feed/" rel="self" type="application/rss+xml" />
	<link>http://walterg2.com</link>
	<description>As tools improve, experience declines</description>
	<lastBuildDate>Tue, 12 Jan 2010 19:07:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting More Out of Your UITableViews</title>
		<link>http://walterg2.com/2009/12/09/getting-more-out-of-your-uitableviews/</link>
		<comments>http://walterg2.com/2009/12/09/getting-more-out-of-your-uitableviews/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 04:15:05 +0000</pubDate>
		<dc:creator>walterg2</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Building Your App]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[NIB]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[XIB]]></category>

		<guid isPermaLink="false">http://walterg2.com/?p=80</guid>
		<description><![CDATA[Everyone that has built an iPhone application has at one time or another worked with UITableViews. They are pretty much at the heart of most data intensive applications from Twitter clients to just your standard news app. One thing that&#8217;s not too clear is how do you get more from your tables without jamming (usually [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone that has built an iPhone application has at one time or another worked with UITableViews. They are pretty much at the heart of most data intensive applications from Twitter clients to just your standard news app. One thing that&#8217;s not too clear is how do you get more from your tables without jamming (usually with a sledgehammer and your trusty shoe horn) them into a header of a table section header. There isn&#8217;t much information on the net (at least that I found in my multiple searches) that really goes into how to accomplish this as well.<span id="more-80"></span></p>
<h2>Starting out</h2>
<div id="attachment_81" class="wp-caption alignleft" style="width: 172px"><img class="size-medium wp-image-81" title="iphone-wireframe" src="http://walterg2.com/wp-content/uploads/2009/12/iphone-wireframe-162x300.png" alt="Wireframe of what your business wants" width="162" height="300" /><p class="wp-caption-text">Wireframe of what your business wants</p></div>
<p>So, you&#8217;ve been looking to build a view that is mainly a table, yet has something, maybe some instructional text or even a little description of what the view is for, more to make that view easily understood by the user, but you don&#8217;t want to sacrifice the use of your table header either. Of course, this probably came as a result of some sort of downfall you had seen in a previous application that does similar things, so you&#8217;re sold on this being the &#8220;right&#8221; way to do it.</p>
<p>But how do you actually do this and ensure that the view scrolls not just the table, but everything in that view? This was something I struggled with for a few hours, Trying time and time again to manpulate a UIScrollView XIB with a UITableView nested inside. All that did was override the scroll features of the UIScrollView to the UITableView, making the only thing you can scroll the table; not the entire view as desired. Before you lose all of your hair as to why, it&#8217;s basically due to the UITableView being a subclass of UIScrollView.</p>
<h2>How it&#8217;s done</h2>
<p>OK, now that we&#8217;re past trying to get our way through force, let&#8217;s get try some finesse. Given that we&#8217;re really trying to add more information to a UITableView, so why don&#8217;t we try something along those lines. First, we need to create the classes and XIB that will be our view when we&#8217;re done. Do this as you normally would by choosing <strong>File</strong> -&gt; <strong>New File</strong> or <strong>Command-N</strong> if you&#8217;re keyboard motivated. When the New File screen comes up, choose <strong>Cocoa Touch Class</strong> under the iPhone OS section, then <strong>UIViewController subclass</strong>. Make sure you check the two options available; <strong>UITableViewController subclass</strong> and <strong>With XIB for user interface</strong>. Choose <strong>Next</strong>, and create the <strong>.m</strong> and <strong>.h</strong> files.</p>
<p><img class="size-medium wp-image-85 alignright" title="interface-builder-table-view-nib" src="http://walterg2.com/wp-content/uploads/2009/12/interface-builder-table-view-nib-300x299.png" alt="interface-builder-table-view-nib" width="300" height="299" />Now you should have three files available to you: your .m, .h and .xib file so it&#8217;s time to make the XIB do what we want. Open the XIB file either by double-clicking it in XCode, or manually by opening Interface Builder, finding the file and opening the XIB file. To add in the necessary label which is the root of all this additional work, we simply need to do only two more things.</p>
<h2>The two steps</h2>
<p><img class="alignleft size-medium wp-image-86" title="interface-builder-table-view-with-label" src="http://walterg2.com/wp-content/uploads/2009/12/interface-builder-table-view-with-label-300x299.png" alt="interface-builder-table-view-with-label" width="300" height="299" />The first thing to do is to add a UIView as a child of your Table View. Easy enough, just find the UIView in the Library within Interface Builder and drag it into your XIB view where you&#8217;re looking to drop it. Simple enough. The next step is just as simple. We need to add the label. Again, find the Label in the Library and drag it under your UIView that you just added.</p>
<p>I&#8217;m sure you&#8217;re thinking, &#8220;It can&#8217;t be that simple, can it?&#8221; Well, believe it or not, it is. When I figured this out, it was just a shot in the dark as I had first tried everything I could think of by using a UIScrollView and embedding a table inside of it.</p>
<p>There is still a little formatting you will need to do to ensure your view and it&#8217;s label have enough space at the top of your view. But, once you&#8217;re done though, you should have the view of your XIB looking like the image below. You can also add another view and using simple positioning, place it at the bottom of your view, creating the same effect after your table.</p>
<p><img class="aligncenter size-medium wp-image-84" title="interface-builder-table-view-layout" src="http://walterg2.com/wp-content/uploads/2009/12/interface-builder-table-view-layout-206x299.png" alt="interface-builder-table-view-layout" width="206" height="299" /></p>
<h2>In close</h2>
<p>There are drawbacks, of course. Yes, everything has to have some drawback, nothing is free. The one that you need to be aware of is that you cannot build your code for an iPhone OS under 3.0. If you&#8217;re still building apps for 2.2.1 or below, this would be a great opportunity to change that.</p>
<p>If you&#8217;re wondering what spurred me into finding a solution for the problem at the beginning of this article, it was for an application where the &#8220;My Profile&#8221; tab is able to be updated by the server, so we needed a short label informing users that they can download their profile, but changes are not reflected at the server and a button to start the (potential) login and download processes.</p>
<p style="text-align: center;">
     ]]></content:encoded>
			<wfw:commentRss>http://walterg2.com/2009/12/09/getting-more-out-of-your-uitableviews/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

