<?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>ODM Technology &#187; tableView</title>
	<atom:link href="http://blog.odmtech.com/tag/tableview/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.odmtech.com</link>
	<description>Ord's Blog</description>
	<lastBuildDate>Sat, 04 Jul 2009 15:22:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>iPhone tableView</title>
		<link>http://blog.odmtech.com/2009/03/02/iphone-tableview/</link>
		<comments>http://blog.odmtech.com/2009/03/02/iphone-tableview/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 17:52:27 +0000</pubDate>
		<dc:creator>Ord</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[tableView]]></category>

		<guid isPermaLink="false">http://blog.odmtech.com/?p=45</guid>
		<description><![CDATA[The Table View is widely used in iPhone apps, and ther are many examples of using it on navigation pages in the iPhone SDK example programs.  These examples generally show how to add a tableView that fills the screen, or sometimes with a Navigation  Bar element at the top.
Sometimes, we want to use a table [...]]]></description>
			<content:encoded><![CDATA[<p>The Table View is widely used in iPhone apps, and ther are many examples of using it on navigation pages in the iPhone SDK example programs.  These examples generally show how to add a tableView that fills the screen, or sometimes with a Navigation  Bar element at the top.</p>
<p>Sometimes, we want to use a table view as a smaller element within another view.  The iPhone Clock app uses this approache in stopwatch mode to show the lap times.</p>
<p>In this case, the view that contains the TableView will typically be a subclass of UIViewController.  We need only add the protocols UITableViewDelegate and UITableViewDataSource to our view.  This is done in the header file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &lt;UIKit/UIKit.h&gt;</span>
&nbsp;
@interface MyViewController <span style="color: #339933;">:</span> UIViewController 
  <span style="color: #339933;">&lt;</span>UITableViewDelegate<span style="color: #339933;">,</span> UITableViewDataSource<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
@end</pre></div></div>

<p>For a simple view, we will need to add the numberOfRowsInSection and cellForRowAtIndex methods.  This example shows a table of 5 rows, with cells labeled Item #0 to Item #4.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &quot;MyViewController.h&quot;</span>
&nbsp;
@implementation MyViewController
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>NSInteger<span style="color: #009900;">&#41;</span>tableView<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UITableView <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>tableView
  numberOfRowsInSection<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSInteger<span style="color: #009900;">&#41;</span>section<span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// we want 5 rows in our table.</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>UITableViewCell <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>tableView<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UITableView <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>tableView
     cellForRowAtIndexPath<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>NSIndexPath <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>indexPath<span style="color: #009900;">&#123;</span>
&nbsp;
     NSString <span style="color: #339933;">*</span>Identifier <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#91;</span>NSString alloc<span style="color: #009900;">&#93;</span> initWithFormat<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;Item #%d&quot;</span><span style="color: #339933;">,</span> 
          <span style="color: #009900;">&#91;</span>indexPath indexAtPosition<span style="color: #339933;">:</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
     UITableViewCell <span style="color: #339933;">*</span>cell <span style="color: #339933;">=</span>
          <span style="color: #009900;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #339933;">:</span>Identifier<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cell <span style="color: #339933;">==</span> nil<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          cell <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#91;</span>UITableViewCell alloc<span style="color: #009900;">&#93;</span> 
               initWithFrame<span style="color: #339933;">:</span>CGRectZero reuseIdentifier<span style="color: #339933;">:</span> Identifier<span style="color: #009900;">&#93;</span> 
               autorelease<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
     cell.<span style="color: #202020;">text</span> <span style="color: #339933;">=</span> Identifier<span style="color: #339933;">;</span>	
     <span style="color: #b1b100;">return</span> cell<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
@end</pre></div></div>

<p>In interface builder, connect the datasource and delegate outlets from your table view directly to file&#8217;s owner.  There is no need to add a tableViewController to the nib.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.odmtech.com/2009/03/02/iphone-tableview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
