<?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>ComSubVie's Creative Content &#187; Tutorial</title>
	<atom:link href="http://markus.ocrs.at/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://markus.ocrs.at</link>
	<description>a blog about computer science, rc-modeling, movies and other things...</description>
	<lastBuildDate>Thu, 18 Jun 2009 13:56:24 +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>Nav Bar Tutorial (Version 2)</title>
		<link>http://markus.ocrs.at/2009/03/13/nav-bar-tutorial-version-2/</link>
		<comments>http://markus.ocrs.at/2009/03/13/nav-bar-tutorial-version-2/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 20:56:22 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=565</guid>
		<description><![CDATA[Das zweite überarbeitete Tutorial beschäftigt sich mit der NavigationBar. Dabei handelt es sich um die Navigationsleiste am oberen Bildschirmrand, mit der man beispielsweise von Detailansichten wieder zur Übersicht zurückkommt, oder beim Bearbeiten von Einträgen die beiden Buttons &#8220;Save&#8221; und &#8220;Cancel&#8221; anzeigt.
Die UINavigationBar verwendet dabei eine Art Stack auf dem UIViewController Objekte abgelegt werden. Bei der [...]]]></description>
			<content:encoded><![CDATA[<p>Das zweite überarbeitete Tutorial beschäftigt sich mit der <em>NavigationBar</em>. Dabei handelt es sich um die Navigationsleiste am oberen Bildschirmrand, mit der man beispielsweise von Detailansichten wieder zur Übersicht zurückkommt, oder beim Bearbeiten von Einträgen die beiden Buttons &#8220;Save&#8221; und &#8220;Cancel&#8221; anzeigt.</p>
<p>Die <tt>UINavigationBar</tt> verwendet dabei eine Art Stack auf dem <tt>UIViewController</tt> Objekte abgelegt werden. Bei der Initialisierung muss in jedem Fall ein <strong>root</strong> ViewController angegeben werden. Dies ist jene View, die am Anfang angezeigt wird.</p>
<p>Mit den Methoden <tt>pushViewController:animated:</tt> sowie <tt>popViewControllerAnimated:</tt> lassen sich zusätzliche <tt>UIViewController</tt> im <tt>UINavigationController</tt> einbinden, wobei die Methode <tt>pushViewController:animated:</tt> den als Parameter angegebenen <tt>UIViewController</tt> anzeigt. Zusätzlich wird automatisch ein <em>Back</em>-Button auf der linken Seite der NavigationBar erzeugt, welcher den Titel des vorigen ViewControllers anzeigt. Die Methode <tt>popViewControllerAnimated:</tt> entfernt den aktuellen ViewController wieder und schaltet auf die vorige Sicht zurück.</p>
<p>Eine View, die in einen <tt>UINavigationController</tt> eingebunden ist, besitzt die Property <tt>navigationItem</tt>, über welche sich die angezeigte <tt>UINavigationBar</tt> modifizieren lässt. So enthält die <tt>UINavigationItem</tt> Klasse die Properties <tt>backBarButtonItem</tt>, <tt>leftBarButtonItem</tt>, <tt>rightBarButtonItem</tt> sowie <tt>title</tt>. Über diese Properties lassen sich die entsprechenden Buttons bzw. der Titel der in der Navigationbar angezeigt wird modifizieren.</p>
<p>Genug der Theorie. Um das Ganze zu demonstrieren möchte ich eine Applikation erstellen, die drei Views enthält, zwischen denen man mit der NavigationBar umschalten kann. Die erste View soll nur einen Add und Details-Button anzeigen, über die zur zweiten View umgeschaltet werden kann. Auf der zweiten View soll es einen Zurück-Button geben, der wieder auf die erste View zurückschaltet sowie einen Edit-Button der auf die dritte View umschaltet. Die dritte View soll die beiden Buttons Cancel (zurück zur zweiten View) und Save (ebenfalls zurück zur zweiten View) enthalten.</p>
<p>Wie immer beginne ich mit einem neuen Projekt vom Typ iPhone OS <strong>Window-Based Application</strong>, welche ich <tt>NavBar</tt> nenne. Dementsprechend erstellt XCode eine Hauptklasse <tt>NavBarAppDelegate.m</tt>.</p>
<p>Zusätzlich erstelle ich die drei Klassen für die drei Views. Diese sind ebenfalls wieder vom Typ <strong>UIViewController subclass</strong>, wobei ich diese wieder <tt>First</tt>, <tt>Second</tt> und <tt>Third</tt> taufe.</p>
<p>Die erste View (<tt>First.m</tt>) soll den Titel <em>First</em> in der NavigationBar anzeigen (Zeile 9) und zusätzlich auf der rechten Seite einen Add-Button (Zeile 10). Zusätzlich wird ein Button in der View angezeigt, der den Titel <em>Details</em> trägt (Zeilen 12-21). Beide Buttons werden mit der Methode <tt>buttonPressed</tt> verbunden (Zeile 10 und 17). Die Methode <tt>buttonPressed</tt> initialisiert die nächste View (also Second, Zeile 25) und zeigt diese über den ViewController an (Zeile 27).</p>
<p><tt>First.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;First.h&quot;</span><br />
<span style="color: #6e371a;">#import &quot;Second.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> First<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadView <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super loadView<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; self.navigationItem.title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span>;<br />
&nbsp; &nbsp; self.navigationItem.rightBarButtonItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithBarButtonSystemItem<span style="color: #002200;">:</span>UIBarButtonSystemItemAdd target<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; UIView <span style="color: #002200;">*</span>tempView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0, 0.0, 320.0, 480.0<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; UIButton <span style="color: #002200;">*</span>button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; button.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>10.0, 10.0, 300.0, 50.0<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>button setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Details&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>tempView addSubview<span style="color: #002200;">:</span>button<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self setView<span style="color: #002200;">:</span>tempView<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>tempView release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; Second <span style="color: #002200;">*</span>second <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Second alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.navigationController pushViewController<span style="color: #002200;">:</span>second animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Die zweite View enthält durch das laden automatisch einen Back-Button auf der rechten Seite der NavigationBar. Zusätzlich muss ein Edit-Button auf der rechten Seite hinzugefügt werden (Zeile 10) und der Titel auf <em>Second</em> gesetzt werden (Zeile 9). Wenn der Back-Button gedrückt wird, schaltet der NavigationController automatisch auf die vorige View zurück. Bei Benutzung des Edit-Buttons (Zeile 8 ) muss äquivalent zur vorigen View eine neue Instanz der nächsten View erzeugt und auf diese umgeschaltet werden (Zeilen 14-16).</p>
<p><tt>Second.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;Second.h&quot;</span><br />
<span style="color: #6e371a;">#import &quot;Third.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> Second<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadView <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super loadView<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; self.navigationItem.title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Second&quot;</span>;<br />
&nbsp; &nbsp; self.navigationItem.rightBarButtonItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithBarButtonSystemItem<span style="color: #002200;">:</span>UIBarButtonSystemItemEdit target<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; Third <span style="color: #002200;">*</span>third <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Third alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.navigationController pushViewController<span style="color: #002200;">:</span>third animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Die letzte View besitzt den Titel <em>Third</em> (Zeile 8 ) sowie zwei Buttons in der Navigationbar (Cancel, Zeile 9 sowie Save, Zeile 10). Beide Buttons lösen einen Rücksprung zur vorigen View aus (Zeile 14):</p>
<p><tt>Third.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;Third.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> Third<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadView <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super loadView<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; self.navigationItem.title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Third&quot;</span>;<br />
&nbsp; &nbsp; self.navigationItem.leftBarButtonItem &nbsp;<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithBarButtonSystemItem<span style="color: #002200;">:</span>UIBarButtonSystemItemCancel target<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; self.navigationItem.rightBarButtonItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithBarButtonSystemItem<span style="color: #002200;">:</span>UIBarButtonSystemItemSave &nbsp; target<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.navigationController popViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Im Hauptprogramm (<tt>NavBarAppDelegate</tt>) muss nun eine Instanz der ersten View (der Root View) erstellt werden (Zeile 11) und ein <tt>UINavigationController</tt> mit dieser initialisiert werden (Zeile 12). Anschließend wird der Navigation Controller als View der Applikation aktiviert (Zeile 14).</p>
<p><tt>NavBarAppDelegate.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;NavBarAppDelegate.h&quot;</span><br />
<span style="color: #6e371a;">#import &quot;First.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> NavBarAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<br />
UINavigationController <span style="color: #002200;">*</span>navController;<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; First <span style="color: #002200;">*</span>firstView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>First alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; navController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationController alloc<span style="color: #002200;">&#93;</span> initWithRootViewController<span style="color: #002200;">:</span>firstView<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>navController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>navController release<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Auch hier erspare ich es mir das ganze Projekt als Source hochzuladen, da auch dieses noch recht trivial ist. Die nächsten geplanten Tutorials sind: Kombination <tt>UITabBar</tt> mit <tt>UINavigationBar</tt>, <tt>UITableView</tt> sowie Delegation. Sowie eventuell etwas über Cocoa-Memorymanagement. Mal schauen&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/03/13/nav-bar-tutorial-version-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tab Bar Tutorial (Version 2)</title>
		<link>http://markus.ocrs.at/2009/03/11/tab-bar-tutorial-version-2/</link>
		<comments>http://markus.ocrs.at/2009/03/11/tab-bar-tutorial-version-2/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 22:26:52 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=561</guid>
		<description><![CDATA[Nachdem ich ja bereits geschrieben habe, dass ich inzwischen vom Interface Builder abgekommen bin (zumindest Großteils; um eine View zu entwerfen und die Daten dann im Code zu übernehmen ist der IB durchaus ganz brauchbar) beginne ich mal mit der ersten Anleitung ohne den IB.
Wie bereits zuvor beginne ich mit einer TabBar Applikation. Dabei soll [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich ja bereits geschrieben habe, dass ich inzwischen vom <em>Interface Builder</em> abgekommen bin (zumindest Großteils; um eine View zu entwerfen und die Daten dann im Code zu übernehmen ist der IB durchaus ganz brauchbar) beginne ich mal mit der ersten Anleitung ohne den IB.</p>
<p>Wie bereits zuvor beginne ich mit einer TabBar Applikation. Dabei soll einfach eine Applikation entstehen, die 2 verschiedene Views enthält, zwischen denen man mit Hilfe einer TabBar umschalten kann. Das grundsätzliche Vorgehen bei der Projekterstellung bleibt dabei gleich, d.h. zuerst wird ein neues Projekt vom Typ iPhone OS <strong>Window-Based Application</strong> erstellt. Da ich die Applikation <tt>TabBar</tt> genannt habe, erzeugt XCode eine Hauptklasse <tt>TabBarAppDelegate.m</tt>.</p>
<p>Zusätzlich dazu erstelle ich zwei weitere Klassen, für jede View eine eigene Klasse, die vom Typ <strong>UIViewController subclass</strong> sind, und die ich sinnvollerweise <tt>First.m</tt> sowie <tt>Second.m</tt> nenne. In jeder dieser beiden Views erstelle ich in der Methode <tt>loadView</tt> ein Label, welches den Text &#8220;First View&#8221; bzw. &#8220;Second View&#8221; anzeigen soll. Diese beiden Klassen sind eigentlich selbsterklärend und sehen wie folgt aus (die Header-Dateien <tt>First.h</tt> und <tt>Second.h</tt> habe ich dabei nicht modifiziert):</p>
<p><tt>First.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;First.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> First<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadView <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super loadView<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; UILabel <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0, 0.0, 320.0, 480.0<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; label.textAlignment <span style="color: #002200;">=</span> UITextAlignmentCenter;<br />
&nbsp; &nbsp; label.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First View&quot;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self setView<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p><tt>Second.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;Second.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> Second<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadView <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super loadView<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; UILabel <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0, 0.0, 320.0, 480.0<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; label.textAlignment <span style="color: #002200;">=</span> UITextAlignmentCenter;<br />
&nbsp; &nbsp; label.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Second View&quot;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self setView<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Im Hauptprogramm, d.h. in der <tt>TabBarAppDelegate</tt> erstelle ich von jedem der beiden ViewController <tt>First</tt> und <tt>Second</tt> eine neue Instanz (Zeile 13 und 14). Ein ViewController besitzt die Property tabBarItem, bei der man den Titel angeben kann (.title), der auf dem zugehörigen Tab dargestellt werden soll, sowie auch ein dazugehöriges Icon (.image). Die beiden Tabs werden hier ebenfalls mit &#8220;First&#8221; und &#8220;Second&#8221; tituliert (Zeile 16 und 17). Anschließend wird ein neuer <tt>UITabBarController</tt> erstellt (Zeile 19) sowie mitgeteilt welche Views (bzw. Tabs) er darstellen soll (Zeile 20). Letztendlich wird dem aktuellen <tt>Window</tt> der Applikation der <tt>UITabBarController</tt> als Subview gesetzt (Zeile 22).</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;TabBarAppDelegate.h&quot;</span><br />
<br />
<span style="color: #6e371a;">#import &quot;First.h&quot;</span><br />
<span style="color: #6e371a;">#import &quot;Second.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> TabBarAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<br />
UITabBarController <span style="color: #002200;">*</span>tabBarController;<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span> &nbsp;<br />
&nbsp; &nbsp; First &nbsp;<span style="color: #002200;">*</span>firstViewController &nbsp;<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>First &nbsp;alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; Second <span style="color: #002200;">*</span>secondViewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Second alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; firstViewController.tabBarItem.title &nbsp;<span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span>;<br />
&nbsp; &nbsp; secondViewController.tabBarItem.title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Second&quot;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; tabBarController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITabBarController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; tabBarController.viewControllers <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span>firstViewController, secondViewController, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>tabBarController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>firstViewController &nbsp;release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>secondViewController release<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>tabBarController release<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Und das war schon die ganze Hexerei. Irgendwie weitaus einfacher und schneller als mit dem Interface Builder, und außerdem weiß man so in etwa was dabei passiert. Da das ganze so trivial ist halte ich es nicht für notwendig ein Archiv des Projektes zum Download zur Verfügung zu stellen, ich kann es bei Bedarf aber durchaus gerne weitergeben.</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/03/11/tab-bar-tutorial-version-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development: Nav Bar Mini HowTo</title>
		<link>http://markus.ocrs.at/2009/02/28/iphone-development-nav-bar-mini-howto/</link>
		<comments>http://markus.ocrs.at/2009/02/28/iphone-development-nav-bar-mini-howto/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 12:49:27 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=531</guid>
		<description><![CDATA[Nachdem sich das letzte Mini HowTo it dem &#8220;Root&#8221;-Navigationselement, der Tab Bar beschäftigt hat, will ich hier die Verwendung der Navigation Bar zeigen. Wenn keine Tab Bar verwendet wird, dann kann die Navigation Bar das &#8220;höchste&#8221; Navigationselement der Anwendung sein, ansonsten muss es in ein View der Tab Bar eingebaut werden.
Beispiele für die Navigation Bar [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem sich das letzte Mini HowTo it dem &#8220;Root&#8221;-Navigationselement, der Tab Bar beschäftigt hat, will ich hier die Verwendung der Navigation Bar zeigen. Wenn keine Tab Bar verwendet wird, dann kann die Navigation Bar das &#8220;höchste&#8221; Navigationselement der Anwendung sein, ansonsten muss es in ein View der Tab Bar eingebaut werden.</p>
<p>Beispiele für die Navigation Bar finden sich in vielen Applikationen, so wird dies zum Beispiel bei den Kontakten verwendet, um einen neuen Kontakt anzulegen, oder um von einem Kontakt wieder auf die Kontaktliste zurückzukommen.</p>
<p>Wie bereits zuvor erwähnt verwende ich für sämtliche Applikationen die Window-Based Application als Vorlage. Äquivalent zur Anwendung der Tab Bar wird die Datei MainWindow.xib im Interface Builder geöffnet und ein Navigation Controller in das Fenster gezogen. Das Resultat sollte dann wie folgt aussehen:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-1.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-532" title="tutorialnavigationbar-bild-1" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-1-150x150.png" alt="tutorialnavigationbar-bild-1" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-2.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-533" title="tutorialnavigationbar-bild-2" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-2-150x150.png" alt="tutorialnavigationbar-bild-2" width="150" height="150" /></a></p>
<p>Anschließend wird dieser Controller im AppDelegate in XCode wieder als IBOutlet hinzugefügt:</p>
<p><tt>TutorialNavigationBarAppDelegate.h</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span><br />
<br />
<span style="color: #a61390;">@interface</span> TutorialNavigationBarAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;UIApplicationDelegate&gt; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UIWindow&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
&nbsp; &nbsp; UINavigationController&nbsp; <span style="color: #002200;">*</span>navController; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWindow <span style="color: #002200;">*</span>window;<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UINavigationController &nbsp; <span style="color: #002200;">*</span>navController; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p><tt>TutorialNavigationBarAppDelegate.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;TutorialNavigationBarAppDelegate.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> TutorialNavigationBarAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<span style="color: #a61390;">@synthesize</span> navController;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>navController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Im Anschluss werden die Outlets im Interface Builder verbunden, d.h. der Navigation Controller wird rechts angeklickt und der Kreis des &#8220;New Referencing Outlet&#8221; auf das Tutorial Navigation Bar App Delegate gezogen. Das Resultat sollte dann wie folgt aussehen:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-3.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-534" title="tutorialnavigationbar-bild-3" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-3-150x150.png" alt="tutorialnavigationbar-bild-3" width="150" height="150" /></a></p>
<p>Die Applikation sollte jetzt bereits laufen und eine leere View mit einer Navigation Bar anzeigen:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-4.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-535" title="tutorialnavigationbar-bild-4" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-4-150x150.png" alt="tutorialnavigationbar-bild-4" width="150" height="150" /></a></p>
<p>Um die Navigation Bar vernünftig verwenden zu können, wird einerseits ein Eingabe-Element benötigt, mit dem auf eine andere View umgeschaltet werden kann, andererseits auch noch diese View, auf die umgeschaltet werden soll.</p>
<p>Im XCode erstelle ich daher eine neue Datei vom Typ &#8220;User Interfaces&#8221; &#8220;View XIB&#8221;, die ich View2.xib taufe.</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-5.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-536" title="tutorialnavigationbar-bild-5" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-5-150x150.png" alt="tutorialnavigationbar-bild-5" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-6.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-537" title="tutorialnavigationbar-bild-6" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-6-150x150.png" alt="tutorialnavigationbar-bild-6" width="150" height="150" /></a></p>
<p>Diese Datei wird nun mit dem Interface Builder geöffnet. Damit diese hier auch der richtigen Größe entspricht, kann man über &#8220;View Attributes&#8221; als Top Bar eine Navigation Bar simulieren.</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-7.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-538" title="tutorialnavigationbar-bild-7" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-7-150x150.png" alt="tutorialnavigationbar-bild-7" width="150" height="150" /></a></p>
<p>Diese View bekommt ein Label, welches ich &#8220;displayText&#8221; taufe, damit man zumindest irgendetwas erkennen kann.</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-8.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-539" title="tutorialnavigationbar-bild-8" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-8-150x150.png" alt="tutorialnavigationbar-bild-8" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-9.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-540" title="tutorialnavigationbar-bild-9" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-9-150x150.png" alt="tutorialnavigationbar-bild-9" width="150" height="150" /></a></p>
<p>Weiters muss für diese View auch wieder ein View Controller erstellt werden. Dazu erstellt man im XCode eine neue Datei vom Typ &#8220;UIViewController subclass&#8221;, die ich View2ViewController taufe.</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-10.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-541" title="tutorialnavigationbar-bild-10" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-10-150x150.png" alt="tutorialnavigationbar-bild-10" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-11.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-542" title="tutorialnavigationbar-bild-11" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-11-150x150.png" alt="tutorialnavigationbar-bild-11" width="150" height="150" /></a></p>
<p>In diesen beiden Dateien erstelle ich ein IBOutlet für das Label, damit man den Text auch modifizieren kann. Die beiden Dateien sehen danach wie folgt aus:</p>
<p><tt>View2ViewController.h</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span><br />
<br />
<span style="color: #a61390;">@interface</span> View2ViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UILabel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>displayText; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UILabel&nbsp; <span style="color: #002200;">*</span>displayText; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p><tt>View2ViewController.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;View2ViewController.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> View2ViewController<br />
<br />
<span style="color: #a61390;">@synthesize</span> displayText;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #11740a; font-style: italic;">/*<br />
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.<br />
- (void)viewDidLoad {<br />
&nbsp; &nbsp; [super viewDidLoad];<br />
}<br />
*/</span><br />
<br />
<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><br />
&nbsp; &nbsp; <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><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Release anything that's not essential, such as cached data</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>View Controller und View müssen im Interface Builder wieder miteinander verbunden werden. Als Class für den &#8220;File&#8217;s Owner&#8221; verwendet man den eben erstellten View2ViewController:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-12.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-543" title="tutorialnavigationbar-bild-12" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-12-150x150.png" alt="tutorialnavigationbar-bild-12" width="150" height="150" /></a></p>
<p>Und das &#8220;New Referencing Outlet&#8221; des displayText Labels mit dem displayText Attribut des &#8220;File&#8217;s Owner&#8221;. Das Resultat sollte dann wie folgt aussehen:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-13.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-544" title="tutorialnavigationbar-bild-13" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-13-150x124.png" alt="tutorialnavigationbar-bild-13" width="150" height="124" /></a></p>
<p>Außerdem muss noch das View Attribut des &#8220;File&#8217;s Owner&#8221; mit der View verbunden werden. Dazu wird der &#8220;File&#8217;s Owner&#8221; rechts angeklickt, und der Kreis neben &#8220;view&#8221; auf die View gezogen. Das Ergebnis sollte so aussehen:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-14.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-545" title="tutorialnavigationbar-bild-14" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-14-150x150.png" alt="tutorialnavigationbar-bild-14" width="150" height="150" /></a></p>
<p>Die Umschaltung auf diese View muss nun irgendwie ausgelöst werden, daher füge ich in der MainWindow.xib einen Button hinzu (im Normalfall wird dies vermutlich eher aus einer TableView geschehen), den ich detailsButton taufe. Das sieht im Interface Builder dann wie folgt aus:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-15.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-546" title="tutorialnavigationbar-bild-15" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-15-150x150.png" alt="tutorialnavigationbar-bild-15" width="150" height="150" /></a></p>
<p>Wie man an diesem Bild erkennen kann, wird die View durch den Button ersetzt. Wenn man eine eigene View einsetzen will (was ich durchaus als sinnvoll erachte), so sollte man dem View Controller hier eine eigene XIB Datei angeben (allerdings bin ich mir nicht ganz sicher ob das funktioniert, weil es beim Tab Bar Controller ja nicht geklappt hat).</p>
<p>Anschließend füge ich die Outlets und die Action im AppDelegate ein (eine eigene View hätte hier den Vorteil, das die App Delegate nicht so überfüllt ist). Zustätzlich muss auch die neue View hier eingetragen werden. Die neuen App Delegate Dateien sehen dann so aus:</p>
<p><tt>TutorialNavBarAppDelegate.h</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span><br />
<br />
<span style="color: #6e371a;">#import &quot;View2ViewController.h&quot;</span><br />
<br />
<span style="color: #a61390;">@interface</span> TutorialNavigationBarAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;UIApplicationDelegate&gt; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UIWindow&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
&nbsp; &nbsp; UINavigationController&nbsp; <span style="color: #002200;">*</span>navController;<br />
<br />
&nbsp; &nbsp; UIButton&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>detailsButton; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
&nbsp; &nbsp; View2ViewController &nbsp; &nbsp; <span style="color: #002200;">*</span>view2Controller; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWindow &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UINavigationController &nbsp; <span style="color: #002200;">*</span>navController;<br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIButton &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>detailsButton; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> View2ViewController &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>view2Controller; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p><tt>TutorialNavBarAppDelegate.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;TutorialNavigationBarAppDelegate.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> TutorialNavigationBarAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<span style="color: #a61390;">@synthesize</span> navController;<br />
<span style="color: #a61390;">@synthesize</span> detailsButton;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@synthesize</span> view2Controller;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// BLOCK ADDED</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> view2Controller <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; view2Controller <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>View2ViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;View2&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>view2Controller displayText<span style="color: #002200;">&#93;</span>.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Details&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>navController pushViewController<span style="color: #002200;">:</span>view2Controller animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>navController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Die buttonPressed Methode erzeugt eine neue View auf Basis des View2ViewControllers mit der View2 XIB als Resource, wobei der Text des Labels mit &#8220;Details&#8221; beschriftet wird. Anschließend wird der Navigation Controller aufgefordert, die View entsprechend umzuschalten.</p>
<p>Im Anschluss werden die ganzen Dinge wieder im Interface Builder verbunden, d.h. das &#8220;New Referencing Outlet&#8221; des detailsButton mit dem Tutorial Nav Bar App Delegate displayButton Attribut und das Touch Down Event des detailsButton mit der buttonPressed Methode des Tutorial Nav Bar App Delegates. Das Resultat ist hier dargestellt:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-16.png" rel="lightbox[531]"><img class="aligncenter size-thumbnail wp-image-547" title="tutorialnavigationbar-bild-16" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-16-150x150.png" alt="tutorialnavigationbar-bild-16" width="150" height="150" /></a></p>
<p>Das fertige Resultat sollte nun so aussehen:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-17.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-548" title="tutorialnavigationbar-bild-17" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-17-150x150.png" alt="tutorialnavigationbar-bild-17" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-18.png" rel="lightbox[531]"><img class="alignnone size-thumbnail wp-image-549" title="tutorialnavigationbar-bild-18" src="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar-bild-18-150x150.png" alt="tutorialnavigationbar-bild-18" width="150" height="150" /></a></p>
<p>Falls man einen Add Button einsetzen will, muss man dies in der viewDidLoad Methode des entsprechenden ViewControllers hinzufügen (bei diesem Beispiel funktioniert dies daher nur im View2ViewController, da die Startseite keine eigene View besitzt). Der folgende Code erledigt dies:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> addButtonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// TODO Add Implementation</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; self.navigationItem.rightBarButtonItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithBarButtonSystemItem<span style="color: #002200;">:</span>UIBarButtonSystemItemAdd target<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addButtonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Hier ist nun wieder der komplette Code des Beispiels: <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialnavigationbar.zip">TutorialNavBar (ZIP-Archiv)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/02/28/iphone-development-nav-bar-mini-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development: Tab Bar Mini HowTo</title>
		<link>http://markus.ocrs.at/2009/02/27/iphone-development-tab-bar-mini-howto/</link>
		<comments>http://markus.ocrs.at/2009/02/27/iphone-development-tab-bar-mini-howto/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 22:25:44 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=513</guid>
		<description><![CDATA[Das Interface des iPhones ist in mehrere verschiedene Komponenten unterteilt. Die Tab Bar ist dabei jene Komponenten, die am unteren Rand des Displays angezeigt wird, und zwischen verschiedenen Darstellungen umschaltet.
Beim Telefon ist dies beispielswiese Favoriten, Anrufliste, Kontakte, Ziffernblock und Voicemail; bei der Uhr Weltuhr, Wecker, Stoppuhr sowie Timer.
Eine Tab Bar ist das &#8220;höchste&#8221; Navigationselement am [...]]]></description>
			<content:encoded><![CDATA[<p>Das Interface des iPhones ist in mehrere verschiedene Komponenten unterteilt. Die Tab Bar ist dabei jene Komponenten, die am unteren Rand des Displays angezeigt wird, und zwischen verschiedenen Darstellungen umschaltet.</p>
<p>Beim Telefon ist dies beispielswiese Favoriten, Anrufliste, Kontakte, Ziffernblock und Voicemail; bei der Uhr Weltuhr, Wecker, Stoppuhr sowie Timer.</p>
<p>Eine Tab Bar ist das &#8220;höchste&#8221; Navigationselement am iPhone. D.h. wenn eine Tab Bar verwendet werden soll, so sind alle anderen Ansichten dieser untergeordnet. Daher muss bei einer Applikation mit Tab Bar basierter Navigation diese Tab Bar als erstes Element implementiert werden.</p>
<p>Für sämtliche Applikationen am iPhone verwende ich die Window-Based Application als Vorlage. Diese generiert nur eine AppDelegate Klasse für die Anwendung sowie eine MainWindow.xib Datei, die das Interface definiert:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-1-new-project-template.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-514" title="bild-1-new-project-template" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-1-new-project-template-150x150.png" alt="bild-1-new-project-template" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-2-new-project-name.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-515" title="bild-2-new-project-name" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-2-new-project-name-150x150.png" alt="bild-2-new-project-name" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-3-initial-project.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-516" title="bild-3-initial-project" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-3-initial-project-150x150.png" alt="bild-3-initial-project" width="150" height="150" /></a></p>
<p>Um eine Tab Bar zu verwenden, wird zuerst die Datei MainWindow.xib im Interface Builder geöffnet und ein Tab Bar Controller in das Fenster gezogen. Das Resultat sieht wie folgt aus:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-4-ib-mainwindow-xib.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-517" title="bild-4-ib-mainwindow-xib" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-4-ib-mainwindow-xib-150x150.png" alt="bild-4-ib-mainwindow-xib" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-5-ib-tab-bar-controller.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-518" title="bild-5-ib-tab-bar-controller" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-5-ib-tab-bar-controller-150x150.png" alt="bild-5-ib-tab-bar-controller" width="150" height="150" /></a></p>
<p>Anschließend wird im XCode der Controller als IBOutlet hinzugefügt, d.h. die Datei TutorialTabBarAppDelegate.h wie folgt geändert:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span><br />
<br />
<span style="color: #a61390;">@interface</span> TutorialTabBarAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;UIApplicationDelegate&gt; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UIWindow&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
&nbsp; &nbsp; UITabBarController&nbsp; <span style="color: #002200;">*</span>tabBarController;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWindow &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UITabBarController &nbsp; <span style="color: #002200;">*</span>tabBarController;&nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Anschließend wird der Tab Bar Controller als View der Anwendung initialisiert, d.h. die Datei TutorialTabBarAppDelegate.m wie folgt modifiziert:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;TutorialTabBarAppDelegate.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> TutorialTabBarAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<span style="color: #a61390;">@synthesize</span> tabBarController; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>tabBarController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Anschließend geht es wieder zurück zum Interface Builder. Hier wird der Tab Bar Controller rechts angeklickt. Daraufhin erscheint ein Popup-Fenster, in dem man den Kreis neben &#8220;New Referencing Outlet&#8221; auf das Tutorial Tab Bar App Delegate Objekt dragt, wo dann wieder ein Popup mit dem Inhalt &#8220;tabBarController&#8221; erscheint. Dieser tabBarController entspricht der IBOutlet-Variablen, die wir zuvor gerade angelegt haben. Das Resultat sollte wie folgt aussehen:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-6-ib-referencing-outlet.png" rel="lightbox[513]"><img class="aligncenter size-thumbnail wp-image-519" title="bild-6-ib-referencing-outlet" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-6-ib-referencing-outlet-150x150.png" alt="bild-6-ib-referencing-outlet" width="150" height="150" /></a></p>
<p>Die Applikation sollte jetzt bereits laufen und eine funktionierende Tab Bar darstellen:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-7-tutorial-tab-bar-v1.png" rel="lightbox[513]"><img class="aligncenter size-thumbnail wp-image-520" title="bild-7-tutorial-tab-bar-v1" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-7-tutorial-tab-bar-v1-150x150.png" alt="bild-7-tutorial-tab-bar-v1" width="150" height="150" /></a></p>
<p>Damit die ganze Anwendung überhaupt erst Sinn ergibt müssen für die einzelnen Tabs noch entsprechende Inhalte generiert werden. Dazu wird für jedes Tab eine eigene View angelegt.</p>
<p>Dazu wird im XCode eine neue Datei vom Typ UIViewController subclass angelegt, die den Namen &#8220;Tab1ViewController&#8221; erhält:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-8-new-uiviewcontroller-template.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-521" title="bild-8-new-uiviewcontroller-template" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-8-new-uiviewcontroller-template-150x150.png" alt="bild-8-new-uiviewcontroller-template" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-9-new-uiviewcontroller-name.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-522" title="bild-9-new-uiviewcontroller-name" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-9-new-uiviewcontroller-name-150x150.png" alt="bild-9-new-uiviewcontroller-name" width="150" height="150" /></a></p>
<p>Die dadurch erstellten Dateien lasse ich vorerst unangetastet. Weiterhin wird eine Interface Builder Datei für diesen Controller erstellt, d.h. eine neue Datei vom Typ &#8220;View XIB&#8221; mit dem Namen &#8220;Tab1View&#8221; zum Projekt hinzugefügt:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-10-new-uiview-xib-template.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-523" title="bild-10-new-uiview-xib-template" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-10-new-uiview-xib-template-150x150.png" alt="bild-10-new-uiview-xib-template" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-11-new-uiview-xib-name.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-524" title="bild-11-new-uiview-xib-name" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-11-new-uiview-xib-name-150x150.png" alt="bild-11-new-uiview-xib-name" width="150" height="150" /></a></p>
<p>Die Datei Tab1View.xib muss nun mit dem Interface Builder geöffnet werden. Für den &#8220;File&#8217;s Owner&#8221; wird im Identity Inspector als Class das NSObject durch Tab1ViewController ersetzt:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-12-tab1view-identity-inspector.png" rel="lightbox[513]"><img class="aligncenter size-thumbnail wp-image-525" title="bild-12-tab1view-identity-inspector" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-12-tab1view-identity-inspector-150x150.png" alt="bild-12-tab1view-identity-inspector" width="150" height="150" /></a></p>
<p>Anschließend muss das &#8220;New Referencing Outlet&#8221; der View mit dem Attribut view des &#8220;File&#8217;s Owner&#8221; verbunden werden. Dazu dient wieder ein Rechtsklick auf View und ein anschließendes Draggen des Krieses auf &#8220;File&#8217;s Owner&#8221;.</p>
<p>Um die View in der Tutorial-Applikation auch identifizieren zu können, wird ein entsprechendes Label in die View gezogen. Das Resultat sieht im Interface Builder dann so aus:</p>
<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-13-tab1view.png" rel="lightbox[513]"><img class="aligncenter size-thumbnail wp-image-526" title="bild-13-tab1view" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-13-tab1view-150x150.png" alt="bild-13-tab1view" width="150" height="150" /></a></p>
<p>Das View muss nun noch entsprechend in der Tab Bar eingebunden werden. Die Idee dies direkt im Interface Builder zu machen ist zwar naheliegend und funktioniert auch prinzipiell &#8211; zumindest solange bis man dann versucht das Programm auszuführen, dann endet es mit einer Exception. Also muss man doch wieder zum Code greifen. Daher muss die App Delegate wir folgt angepasst werden:</p>
<p><tt>TutorialTabBarAppDelegate.h</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span><br />
<br />
<span style="color: #6e371a;">#import &quot;Tab1ViewController.h&quot;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@interface</span> TutorialTabBarAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;UIApplicationDelegate&gt; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UIWindow&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
&nbsp; &nbsp; UITabBarController&nbsp; <span style="color: #002200;">*</span>tabBarController;<br />
<br />
&nbsp; &nbsp; Tab1ViewController&nbsp; <span style="color: #002200;">*</span>tab1ViewController;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWindow &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>window;<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UITabBarController &nbsp; <span style="color: #002200;">*</span>tabBarController;<br />
<br />
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> Tab1ViewController&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>tab1ViewController;<span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p><tt>TutorialTabBarAppDelegate.m</tt>:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;TutorialTabBarAppDelegate.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> TutorialTabBarAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<span style="color: #a61390;">@synthesize</span> tabBarController;<br />
<br />
<span style="color: #a61390;">@synthesize</span> tab1ViewController; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINE ADDED</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; tab1ViewController <span style="color: #002200;">=</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// LINES ADDED</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Tab1ViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Tab1View&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>tabBarController viewControllers<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span>0<span style="color: #002200;">&#93;</span> view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>tab1ViewController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>tabBarController view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<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><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Äquivalent wird ein Tab2ViewController sowie eine Tab2View angelegt sowie im AppDelegate eingebaut. Das fertige Programm sieht dann wie folgt aus:</p>
<p style="text-align: center;"><a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-14-finished-tab-1.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-527" title="bild-14-finished-tab-1" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-14-finished-tab-1-150x150.png" alt="bild-14-finished-tab-1" width="150" height="150" /></a> <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-15-finished-tab-2.png" rel="lightbox[513]"><img class="alignnone size-thumbnail wp-image-528" title="bild-15-finished-tab-2" src="http://markus.ocrs.at/wp-content/uploads/2009/02/bild-15-finished-tab-2-150x150.png" alt="bild-15-finished-tab-2" width="150" height="150" /></a></p>
<p>Der fertige Sourcecode des Programms ist hier als Download verfügbar: <a href="http://markus.ocrs.at/wp-content/uploads/2009/02/tutorialtabbar.zip">TutorialTabBar (ZIP-Archiv)</a></p>
<p>Viel Erfolg beim Programmieren!</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/02/27/iphone-development-tab-bar-mini-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
