<?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; Programmieren</title>
	<atom:link href="http://markus.ocrs.at/category/computer/programmieren/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>iPhone OS / SDK 3.0</title>
		<link>http://markus.ocrs.at/2009/03/18/iphone-os-sdk-30/</link>
		<comments>http://markus.ocrs.at/2009/03/18/iphone-os-sdk-30/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 14:55:19 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=576</guid>
		<description><![CDATA[Nachdem gestern ja das neue iPhone OS vorgestellt wurde, habe ich mir dieses gleich einmal näher angeschaut (allerdings werde ich es nicht so schnell installieren, da die meisten der neuen Features für meine Applikationen jetzt nicht wirklich wesentlich von Bedeutung sind &#8211; ich hab zwar schon ein paar Ideen, aber das reicht glaub ich wenn [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://markus.ocrs.at/wp-content/uploads/2009/03/iphone-3-new-1jpg.jpeg" rel="lightbox[576]"><img class="aligncenter size-medium wp-image-577" title="iphone-3-new-1jpg" src="http://markus.ocrs.at/wp-content/uploads/2009/03/iphone-3-new-1jpg-300x233.jpg" alt="iphone-3-new-1jpg" width="300" height="233" /></a>Nachdem gestern ja das neue iPhone OS vorgestellt wurde, habe ich mir dieses gleich einmal näher angeschaut (allerdings werde ich es nicht so schnell installieren, da die meisten der neuen Features für meine Applikationen jetzt nicht wirklich wesentlich von Bedeutung sind &#8211; ich hab zwar schon ein paar Ideen, aber das reicht glaub ich wenn ich das implementiere wenn alles andere schon fertig ist).</p>
<p>Bei der Übersicht der neuen Features wären mir die folgenden Dinge aufgefallen:</p>
<ul>
<li>Bluetooth Kommunikation zwischen den Geräten</li>
<li>Zugriff auf über das Dock angeschlossene Hardware (ich hab die dazugehörige ExternalAccessory API aber noch nicht wirklich durchblickt)</li>
<li>CoreData (ich werd das zwar nicht so schnell verwenden, aber prinzipiell ist das ganz nett, und könnte möglicherweise das Synchen zwischen iPhone- und Desktop-Applikationen erleichtern bzw. auf einfache Weise auf beiden Seiten die gleichen Datenrepräsentation ermöglichen)</li>
<li>CoreLocation erlaut Turn-by-Turn Anweisungen (allerdings nicht in Google Maps, aber ich vermute dass damit TomTom &amp; Co demnächst im AppStore verfügbar sein wird)</li>
<li>Push notifications (ich glaub zwar nicht das ich die so schnell brauchen werde, aber auf dieser Basis dürfte demnächst eine Meebo-Applikation erscheinen)</li>
<li>Notes Sync (ich verwende zwar mittlerweile Things, aber das ist trotzdem schon lange überfällig)</li>
</ul>
<p>Eine detaillierte Liste an API Änderungen ist (für Developer) auch verfügbar &#8211; die ist wirklich recht lang. Die interessantesten sind dabei:</p>
<ul>
<li>CoreFoundation: NSPredicate wurde hinzugefügt. Letztens habe ich mich über dessen Fehlen geärgert, weil das Filtern von UITableViews mit NSPredicate einfacher wäre als ohne. Ein entsprechendes Beispiel wird es früher oder später hier im UITableView Tutorial geben (sobald ich dieses erstellt habe).</li>
<li>GameKit ist meiner Meinung nach ein bisschen komisch benannt, weil das nicht nur für Spiele interessant ist:<br />
<blockquote><p>The GKPeerPickerController class provides a standard user interface to allow a user to connect their iPhone to another user’s iPhone. The user can select between local Bluetooth connections and internet connections.</p></blockquote>
</li>
<li>MapKit erlaubt es Google Maps in eigene Applikationen einzubauen.</li>
<li>UIKit hat einige interessante Erweiterungen erfahren: einige Navigationselemente lassen sich nun leicht transparent schalten.
<ul>
<li>UITableView: <tt>reloadRowsAtIndexPaths:withRowAnimation:</tt>, <tt>reloadSectionIndexTitles</tt>, <tt>reloadSections:withRowAnimation:</tt> erlauben es bei Anpassungen an der DataSource nur die relevanten Abschnitte neu zu laden, sodass nicht mehr die ganze UITableView neu geladen werden muss.</li>
<li>UITableViewCell: hier sind einige der bisher vorhandenen (und zu verwendenden) Properties inzwischen deprecated (so ist statt .text inzwischen .textLabel und .detailTextLabel zu verwenden)</li>
</ul>
</li>
</ul>
<p>Ansonsten sind mir jetzt für Developer keine wesentlichen Änderungen aufgefallen (zumindest nicht in Bereichen mit denen ich mich inzwischen beschäftigt habe).</p>
<p>Ich bin mir zwar nicht ganz sicher, inwieweit man das überhaupt veröffentlichen darf, da auf der Developer-Seite steht:</p>
<blockquote><p>iPhone SDK 3.0 and iPhone OS 3.0 beta are pre-release software and are considered Apple Confidential Information. Any information Apple collects is subject to the terms of the Apple privacy policy.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/03/18/iphone-os-sdk-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Slow Blogging Days</title>
		<link>http://markus.ocrs.at/2009/03/05/slow-blogging-days/</link>
		<comments>http://markus.ocrs.at/2009/03/05/slow-blogging-days/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 08:40:58 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Dieses Blog]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[CreativeContent]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=559</guid>
		<description><![CDATA[Ich hab gerade auf Rebel Science News gelesen:
I am intensely involved in a programming project and I am finding it hard to change my focus to other matters. As a result, my blogging activities will be less frequent. Please bear with me.
Das kann ich nur unterschreiben. Aber mein Programm macht durchaus Fortschritte. Außerdem sollte ich [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hab gerade auf <a href="http://rebelscience.blogspot.com/">Rebel Science News</a> gelesen:</p>
<blockquote><p>I am intensely involved in a programming project and I am finding it hard to change my focus to other matters. As a result, my blogging activities will be less frequent. Please bear with me.</p></blockquote>
<p>Das kann ich nur unterschreiben. Aber mein Programm macht durchaus Fortschritte. Außerdem sollte ich jetzt demnächst neue iPhone-HowTo&#8217;s (ohne Interface Builder) posten, aber im Moment bin ich eher mim programmieren beschäftigt (und Diplomarbeit sollt ich wohl auch irgendwann mal machen).</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/03/05/slow-blogging-days/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development: Current Status</title>
		<link>http://markus.ocrs.at/2009/03/01/iphone-development-current-status/</link>
		<comments>http://markus.ocrs.at/2009/03/01/iphone-development-current-status/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 22:18:14 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=553</guid>
		<description><![CDATA[Nachdem ich ja letztens 2 kurze Tutorials geschrieben habe, bin ich dann irgendwann draufgekommen, das das ganze dann doch nicht so einfach ist. Da ich ja nach wie vor damit beschäftigt bin, meine FlightLog-Applikation zu schreiben, musste ich feststellen, dass das mit dem Interface Builder irgendwie nicht immer so hinhaut wie man es erwarten sollte. [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich ja letztens 2 kurze Tutorials geschrieben habe, bin ich dann irgendwann draufgekommen, das das ganze dann doch nicht so einfach ist. Da ich ja nach wie vor damit beschäftigt bin, meine FlightLog-Applikation zu schreiben, musste ich feststellen, dass das mit dem Interface Builder irgendwie nicht immer so hinhaut wie man es erwarten sollte. Daher verwende ich diesen nur noch in seltenen Fällen.</p>
<p>Demzufolge wird es demnächst auch ein neues HowTo geben, wie man Tab Bar + Navigation Bar + TableView + SQLite verwendet, um was-auch-immer zu machen. Allerdings wird dies wohl noch ein Zeiterl dauern&#8230; (und irgendwie sollte ich nebenbei auch noch schauen, das meine Diplomarbeit fertig wird).</p>
<p>Hier dennoch 2 Screenshots vom aktuellen Status meiner Applikation (die Daten kommen bereits aus einer SQLite Datenbank):</p>

<a href='http://markus.ocrs.at/2009/03/01/iphone-development-current-status/bild-2-2/' title='bild-2'><img width="150" height="150" src="http://markus.ocrs.at/wp-content/uploads/2009/03/bild-2-150x150.png" class="attachment-thumbnail" alt="" title="bild-2" /></a>
<a href='http://markus.ocrs.at/2009/03/01/iphone-development-current-status/bild-3-2/' title='bild-3'><img width="150" height="150" src="http://markus.ocrs.at/wp-content/uploads/2009/03/bild-3-150x150.png" class="attachment-thumbnail" alt="" title="bild-3" /></a>

]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/03/01/iphone-development-current-status/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>
		<item>
		<title>Siftables</title>
		<link>http://markus.ocrs.at/2009/02/15/siftables/</link>
		<comments>http://markus.ocrs.at/2009/02/15/siftables/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:30:41 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Wissenschaft]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[MIT]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=434</guid>
		<description><![CDATA[Siftables sind eine Entwicklung des MIT Media Lab. Im Prinzip handelt es sich dabei um Mini-Computer mit eingebautem Bildschirm, die Beschleunigungssensoren beinhalten und erkennen wenn sie sich nahe kommen. Man kann daher auf jedem der Bausteine irgendwelche Informationen darstellen, und durch physikalische Nähe der Bausteine diese miteinander interagieren lassen. Ein entsprechendes Beispiel dafür ist die [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.siftables.com/">Siftables</a> sind eine Entwicklung des <a href="http://www.media.mit.edu/">MIT Media Lab</a>. Im Prinzip handelt es sich dabei um Mini-Computer mit eingebautem Bildschirm, die Beschleunigungssensoren beinhalten und erkennen wenn sie sich nahe kommen. Man kann daher auf jedem der Bausteine irgendwelche Informationen darstellen, und durch physikalische Nähe der Bausteine diese miteinander interagieren lassen. Ein entsprechendes Beispiel dafür ist die Generierung der Fibonacci-Sequenz:</p>
<p style="text-align: center;"><object width="400" height="225" data="http://vimeo.com/moogaloop.swf?clip_id=3164229&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=3164229&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /></object></p>
<p>Ebenso genial finde ich den Music Sequencer:</p>
<p style="text-align: center;"><object width="400" height="225" data="http://vimeo.com/moogaloop.swf?clip_id=3165011&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=3165011&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /></object></p>
<p>Das ganze Projekt wurde (sehr gut) in einer TED Präsentation vorgeführt:</p>
<p style="text-align: center;"><object width="446" height="326" data="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /><param name="bgColor" value="#ffffff" /><param name="flashvars" value="vu=http://video.ted.com/talks/embed/DavidMerrill_2009-embed_high.flv&amp;su=http://images.ted.com/images/ted/tedindex/embed-posters/DavidMerrill-2009.embed_thumbnail.jpg&amp;vw=432&amp;vh=240&amp;ap=0&amp;ti=457" /><param name="src" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" /><param name="bgcolor" value="#ffffff" /><param name="allowfullscreen" value="true" /></object></p>
<p>Ich bin mir zwar noch nicht wirklich sicher, ob es für das ganze sinnvolle Anwendungen gibt, aber ich finde es trotzdem ziemlich cool. Ich will sowas haben &#8211; auch wenn ich nicht weiß was ich damit machen soll&#8230;</p>
<p>Nähere Informationen finden sich im <a href="http://blog.tacolab.com/">Taco Lab Blog</a> und auf der <a href="http://www.siftables.com/">Homepage</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/02/15/siftables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming is hard</title>
		<link>http://markus.ocrs.at/2009/02/12/programming-is-hard/</link>
		<comments>http://markus.ocrs.at/2009/02/12/programming-is-hard/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 19:55:03 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=415</guid>
		<description><![CDATA[Bei meinen mehr-oder-weniger täglichen Blog-Exkursionen bin ich heute über Jon Skeed: Coding Blog gestolpert (igitt, ASP). Für .net Programmierer sicher sehr lesenswert, für alle anderen nicht so der Bringer. Aber den Artikel Programming is hard fand ich ganz nett:


If your code deals with arbitrary human text, it&#8217;s probably broken. (Have you taken the Turkey test recently?)
If your [...]]]></description>
			<content:encoded><![CDATA[<p>Bei meinen mehr-oder-weniger täglichen Blog-Exkursionen bin ich heute über <a href="http://msmvps.com/blogs/jon_skeet/default.aspx">Jon Skeed: Coding Blog</a> gestolpert (igitt, ASP). Für .net Programmierer sicher sehr lesenswert, für alle anderen nicht so der Bringer. Aber den Artikel <a href="http://msmvps.com/blogs/jon_skeet/archive/2009/01/29/programming-is-hard.aspx">Programming is hard</a> fand ich ganz nett:</p>
<blockquote>
<ul>
<li>If your code deals with arbitrary human text, it&#8217;s probably broken. (Have you taken the <a href="http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html">Turkey test</a> recently?)</li>
<li>If your code deals with floating point numbers, it&#8217;s probably broken.</li>
<li>If your code deals with concurrency (whether that means database transactions, threading, whatever), it&#8217;s probably broken.</li>
<li>If your code deals with dates, times and time zones, it&#8217;s probably broken. (Time zones in particular are hideous.)</li>
<li>If your code has a user interface with anything other than a fixed size and a fixed set of labels (no i18n), it&#8217;s probably broken.</li>
</ul>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/02/12/programming-is-hard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teensy AVR &amp; Mac AVR-GCC</title>
		<link>http://markus.ocrs.at/2009/01/30/teensy-avr-mac-avr-gcc/</link>
		<comments>http://markus.ocrs.at/2009/01/30/teensy-avr-mac-avr-gcc/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 09:52:42 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=294</guid>
		<description><![CDATA[Ich habe gerade ein recht günstiges AVR Starterkit gefunden, das Teensy USB Development Board ($19), welches einen AVR AT90USB162 beinhaltet (ok, ein ATxmega irgendwas wäre mir lieber, aber immerhin), einige I/O Pins beinhaltet und direkt über USB programmiert werden kann (unter allen gängigen Betriebssystemen, inclusive OS X).
Zusätzlich habe ich das AVR MacPack entdeckt, welches im [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe gerade ein recht günstiges AVR Starterkit gefunden, das <a href="http://www.pjrc.com/teensy/">Teensy USB Development Board</a> ($19), welches einen AVR AT90USB162 beinhaltet (ok, ein ATxmega irgendwas wäre mir lieber, aber immerhin), einige I/O Pins beinhaltet und direkt über USB programmiert werden kann (unter allen gängigen Betriebssystemen, inclusive OS X).</p>
<p>Zusätzlich habe ich das <a href="http://www.obdev.at/products/avrmacpack/download.html">AVR MacPack</a> entdeckt, welches im Prinzip nur der AVR GCC für OS X ist. Das ist zumindest für jene Leute interessant, die AVRs programmieren wollen, aber die benötigte Software nicht unbedingt über DarwinPorts installieren wollen. Das MacPack scheint auch regelmäßig aktualisiert zu werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/30/teensy-avr-mac-avr-gcc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java ist komisch</title>
		<link>http://markus.ocrs.at/2009/01/29/java-ist-komisch/</link>
		<comments>http://markus.ocrs.at/2009/01/29/java-ist-komisch/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 22:59:58 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=286</guid>
		<description><![CDATA[Nachdem wir heute am TGM eine kleine Diskussion hatten, wobei der Christoph behauptet hat, dass man in Java zu einem char kein int addieren kann, und ich das einfach nicht glauben konnte, musste ich das gleich mal probieren. Und er hatte fast recht. Beim ersten Versuch gelang es mir nicht, den Fehler zu erzeugen, aber [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem wir heute am TGM eine kleine Diskussion hatten, wobei der Christoph behauptet hat, dass man in Java zu einem <tt>char</tt> kein <tt>int</tt> addieren kann, und ich das einfach nicht glauben konnte, musste ich das gleich mal probieren. Und er hatte fast recht. Beim ersten Versuch gelang es mir nicht, den Fehler zu erzeugen, aber ich habe es dann doch geschafft:</p>
<p>Wenn man (also typischer Java-Programmierer, also nicht schreibfaul) programmiert ist das eigentlich einfach zu erreichen. Der folgende Code liefert beim Kompilieren eine entsprechende Fehlermeldung (<em>possible loss of precision</em> - was ja durchaus nicht falsch ist, wobei das eigentlich nur eine Warnung sein sollte, und kein Fehler, aber da ist Java ja sowieso ein bisschen komisch):</p>
<div class="codecolorer-container java 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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> args <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> zeichen <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; zeichen <span style="color: #339933;">=</span> zeichen <span style="color: #339933;">+</span> x<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> zeichen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Wobei die vom C-Programmierer favorisierte kurze Schreibweise (die auch mein erster Versuch war) problemlos funktioniert und beim Ausführen auch das erwartete Ergebnis zurückliefert:</p>
<div class="codecolorer-container java 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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> args <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> zeichen <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; zeichen <span style="color: #339933;">+=</span> x<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> zeichen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Eine alternative funktionierende Lösung wäre ein entsprechendes Casten:</p>
<div class="codecolorer-container java 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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> args <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> zeichen <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; zeichen <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>zeichen <span style="color: #339933;">+</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> zeichen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Abschließend kann man sagen, dass sich Java da zwar schon ein bisschen seltsam verhält (es bringt zum Beispiel auch nichts nur das <tt>x</tt> auf <tt>char</tt> zu casten, man muss das Ergebnis der Addition casten. Aber zumindest funktioniert eine Addition sehr wohl, wobei die Nichtfunktionalität ja eh niemand so wirklich glauben wollte&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/29/java-ist-komisch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Musiker &amp; Programmierer</title>
		<link>http://markus.ocrs.at/2009/01/21/musiker-programmierer/</link>
		<comments>http://markus.ocrs.at/2009/01/21/musiker-programmierer/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 21:05:52 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Kunst]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Musik]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=199</guid>
		<description><![CDATA[Nachdem ich ja doch den einen oder anderen Musiker kenne, der auch programmiert (Hallo Christoph!), und ich meine tägliche Portion Coding Horror lese, ist mir natürlich der Artikel The One Thing Programmers and Musicians Have In Common aufgefallen. Ist jetzt nicht unbedingt ein weltbewegender Artikel, ist auch nicht sonderlich lang &#8211; wenn man mal von den Kommentaren [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich ja doch den einen oder anderen Musiker kenne, der auch programmiert (Hallo Christoph!), und ich meine tägliche Portion <a href="http://www.codinghorror.com/">Coding Horror</a> lese, ist mir natürlich der Artikel <a class="title-link" href="http://www.codinghorror.com/blog/archives/001214.html">The One Thing Programmers and Musicians Have In Common</a> aufgefallen. Ist jetzt nicht unbedingt ein weltbewegender Artikel, ist auch nicht sonderlich lang &#8211; wenn man mal von den Kommentaren absieht, aber für die musikinteressierten Programmierer durchaus einen Blick wert&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/21/musiker-programmierer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Byte of Vim</title>
		<link>http://markus.ocrs.at/2009/01/20/a-byte-of-vim/</link>
		<comments>http://markus.ocrs.at/2009/01/20/a-byte-of-vim/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 19:41:56 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Literatur]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[Vi]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=197</guid>
		<description><![CDATA[Ich bin gerade auf ein (online) Buch über den Vi(m) gestoßen: A Byte of Vim. Die Kurzbeschreibung des Buches lautet wie folgt:
&#8220;A Byte of Vim&#8221; is a book which aims to help you to learn how to use the Vim editor (version 7), even if all you know is how to use the computer keyboard.
The [...]]]></description>
			<content:encoded><![CDATA[<p>Ich bin gerade auf ein (online) Buch über den Vi(m) gestoßen: <a href="http://www.swaroopch.com/notes/Vim#Download">A Byte of Vim</a>. Die Kurzbeschreibung des Buches lautet wie folgt:</p>
<blockquote><p>&#8220;A Byte of Vim&#8221; is a book which aims to help you to learn how to use the Vim editor (version 7), even if all you know is how to use the computer keyboard.</p>
<p>The first part of this book is meant for new users who want to understand what Vim is and learn how to use it.</p>
<p>The second part of this book is for people who already know how to use Vim and want to learn about features that make Vim so powerful, such as windows and tabs, personal information management, making it a programmer&#8217;s editor, how to extend Vim with your own plugins, and more.</p></blockquote>
<p>Ich bin selber noch nicht zum Lesen gekommen, aber ich denke das es sich in jedem Fall auszahlt. Für Leute die Papier bevorzugen lässt sich das Buch auch in gebundener Form bestellen.</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/20/a-byte-of-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Patente: trim()</title>
		<link>http://markus.ocrs.at/2009/01/17/patente-trim/</link>
		<comments>http://markus.ocrs.at/2009/01/17/patente-trim/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 10:30:03 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Patente]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=146</guid>
		<description><![CDATA[Die spinnen die Amis. Es gibt wieder mal ein neues Patent:
Method of automatically removing leading and trailing space characters from data being entered into a database system 
Das ist wohl die klassische trim() Funktion. Patent-Inhaber ist IBM, United States Patent Number 7,475,086. Wobei IBM ja zumindest irgendwann gemeint hat sie würden Software-Patente nicht einklagen (immerhin). Die Kurzbeschreibung:
A [...]]]></description>
			<content:encoded><![CDATA[<p>Die spinnen die Amis. Es gibt wieder mal ein neues Patent:</p>
<blockquote><p>Method of automatically removing leading and trailing space characters from data being entered into a database system </p></blockquote>
<p>Das ist wohl die klassische <tt>trim()</tt> Funktion. Patent-Inhaber ist IBM, <a href="http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&amp;Sect2=HITOFF&amp;d=PALL&amp;p=1&amp;u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&amp;r=1&amp;f=G&amp;l=50&amp;s1=7,475,086.PN.&amp;OS=PN/7,475,086&amp;RS=PN/7,475,086">United States Patent Number 7,475,086</a>. Wobei IBM ja zumindest irgendwann gemeint hat sie würden Software-Patente nicht einklagen (immerhin). Die Kurzbeschreibung:</p>
<blockquote><p>A computer Implemented method of automatically removing space characters from data being entered into a database system are provided. When a user creates a table in a database system into which data having leading and/or trailing character spaces may be entered, the user may specifically instruct the database system to remove any character spaces before entering the data into the table. Consequently, when a piece of data is being entered into the table, the database system will determine whether the piece of data includes leading and/or trailing character spaces. If so, the database system will automatically remove the character spaces from the piece of data before it is entered into the table. Hence, the use of TRIM functions when retrieving data from the database system will be obviated.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/17/patente-trim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interessantes Interface: Zero Chance</title>
		<link>http://markus.ocrs.at/2009/01/16/interessantes-interface-zero-chance/</link>
		<comments>http://markus.ocrs.at/2009/01/16/interessantes-interface-zero-chance/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 16:25:34 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[AppStore]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Programme]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=136</guid>
		<description><![CDATA[Über touchArcade bin ich auf Zero Chance (iTMS-Link) gestoßen (es gibt schon auch viele österreichische iPhone-Entwickler), wobei mir vor allem folgender Absatz ins Auge gestochen hat:
Zero Chance is both a top-down and a 3D third-person game – the orientation of the iPhone or iPod touch determines the perspective.
Das Demo-Video in YouTube demonstriert dies durchaus ansehlich. Ich bin [...]]]></description>
			<content:encoded><![CDATA[<p>Über <a href="http://toucharcade.com/">touchArcade</a> bin ich auf <a href="http://clk.tradedoubler.com/click?p=24380&amp;a=1606960&amp;url=http%3A%2F%2Fitunes.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewSoftware%3Fid%3D301918142%26mt%3D8%26partnerId%3D2003">Zero Chance</a> (iTMS-Link) gestoßen (es gibt schon auch viele österreichische iPhone-Entwickler), wobei mir vor allem folgender Absatz ins Auge gestochen hat:</p>
<blockquote><p><em><span style="font-style: normal;">Zero Chance</span></em> is both a top-down and a 3D third-person game – the orientation of the iPhone or iPod touch determines the perspective.</p></blockquote>
<p>Das Demo-Video in YouTube demonstriert dies durchaus ansehlich. Ich bin mir zwar noch nicht ganz sicher, wie das eigentlich implementiert wurde, aber ich finde diese Perspektiven-Änderung aufgrund der iPhone-Lage durchaus interessant:</p>
<p> </p>
<p><!-- Smart Youtube --><span class="youtube"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ntQRGtoCe1U&amp;rel=1&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=&amp;fs=1&amp;hl=en&amp;autoplay=&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/ntQRGtoCe1U&amp;rel=1&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=&amp;fs=1&amp;hl=en&amp;autoplay=&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="355" ></embed><param name="wmode" value="transparent" /></object></span></p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/16/interessantes-interface-zero-chance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things I Learned the Hard Way</title>
		<link>http://markus.ocrs.at/2009/01/16/things-i-learned-the-hard-way/</link>
		<comments>http://markus.ocrs.at/2009/01/16/things-i-learned-the-hard-way/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 15:07:58 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=123</guid>
		<description><![CDATA[Ich weiß nicht mehr genau wie ich eigentlich auf dieses Blog gestoßen bin, aber es enthält ein paar interessante Artikel. Insbesondere die Reihe Things I Learned the Hard Way finde ich nicht unspannend.
Programmierer
Ein Artikel dieser Reihe &#8211; Programmers are Tiny Gods &#8211; beschäftigt sich mit Programmierern, und wie man mit diesen umgehen sollte.
In Genesis, God [...]]]></description>
			<content:encoded><![CDATA[<p>Ich weiß nicht mehr genau wie ich eigentlich auf <a href="http://powazek.com/">dieses Blog</a> gestoßen bin, aber es enthält ein paar interessante Artikel. Insbesondere die Reihe <a href="http://powazek.com/posts/category/tilthw">Things I Learned the Hard Way</a> finde ich nicht unspannend.</p>
<h3>Programmierer</h3>
<p>Ein Artikel dieser Reihe &#8211; <a href="http://powazek.com/posts/1655">Programmers are Tiny Gods</a> &#8211; beschäftigt sich mit Programmierern, und wie man mit diesen umgehen sollte.</p>
<blockquote><p>In Genesis, God creates things in a certain order. Why plants before animals? I dunno. It just seemed right to Him. (Don’t worry, it’s <a href="http://powazek.com/posts/1606">just a metaphor</a>.)</p>
<p>Programmers are the same way. In any programming language, there will be many ways to solve a problem. The right way to do it is a personal decision, made by the programmer, just like in Genesis.</p>
<p>Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies.</p></blockquote>
<p>Ich muss zugeben, dass ich den letzten Satz hier beim ersten Mal anders gelesen habe: <em>And the tiny universe COMPILES.</em> Außerdem will ich da zwei ganz wichtige Verhaltensgrundregeln wiederholen:</p>
<blockquote><p>So if you’re working with a programmer, you have to treat him or her like a God. You have to pray. You cannot issue edicts. You have to come on bended knee.</p>
<p>if you give a programmer a problem with parameters, they’ll apply every bit of genius they have to solve it in the best possible way. If you tell them <em>how</em> to do it, you’ll suffer the wrath of an angry God.</p></blockquote>
<h3>Designer</h3>
<p>Ein anderer Artikel dieser Reihe &#8211; <a href="http://powazek.com/posts/1629">What&#8217;s Your Suggestion?</a> &#8211; beschäftigt sich mit Designern, und warum diese als Teammitglieder umständlich sein können:</p>
<blockquote><p>If you spent any time in an art-related education, you’ve experienced critique sessions. For the uninitiated, a critique is when you put your hard work on a wall in front of your teacher and peers, and they all rip the living shit out of it.</p>
<p>Critique sessions are rarely about suggesting solutions. In fact, to suggest alternatives would be insulting. It’d be like someone telling Picasso to make all those brush strokes blend in more. Sure, it happens, but it’s not the point. A lot of the criticism in these sessions boils down to “this isn’t working for me. Push harder.”</p>
<p>That’s why most designers make awful team members. It’s why, when the biz dev guy says “this is how our startup is going to make money,” our first inclination is to tear down the idea. We’re in critique mode and that’s just what you do.</p></blockquote>
<p>Das ist eine interessante Feststellung, die ich zumindest nicht widerlegen kann. Als Lösung schlägt er vor, dass Designer ihre Einstellung ändern müssen:</p>
<blockquote><p>Fortunately the solution is simple: just force yourself to come up with an alternate solution.</p>
<p>It’s also become a great mental exercise. When I’m tempted to write that piss-all-over-it email, I think to myself, “so what’s the solution I want to see?” If I can’t come up with one, I won’t send the email. Better to be quiet and see how things progress than to be the negative blocker guy.</p></blockquote>
<p>Das ist sicher nicht nur für Designer eine gute Idee, nur im Unterricht vielleicht nicht immer die ideale Lösung.</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/16/things-i-learned-the-hard-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 5 &amp; enums</title>
		<link>http://markus.ocrs.at/2009/01/16/java-5-enums/</link>
		<comments>http://markus.ocrs.at/2009/01/16/java-5-enums/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 13:02:35 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=121</guid>
		<description><![CDATA[Christoph hat mir letztens einen Link geschickt: No, silly! It&#8217;s an enum! Ich habe mich dabei beim Lesen königlich amüsiert, das könnte durchaus die reale Entstehungsgeschichte der Java-Enums sein. Kurz zusammengefasst:
JLD#3: So an enum is&#8230; a non-instantiable, memberless, final class with subclasses, members and instances?
JLD#2: Yes!
JLD#1: Precisely!
JLD#3: But that&#8217;s just a plain old class!
JLD#1: No, silly! It&#8217;s an enum!
Java ist zum [...]]]></description>
			<content:encoded><![CDATA[<p>Christoph hat mir letztens einen Link geschickt: <a href="http://maycontaintracesofbolts.blogspot.com/2009/01/no-silly-its-enum.html">No, silly! It&#8217;s an enum!</a> Ich habe mich dabei beim Lesen königlich amüsiert, das könnte durchaus die reale Entstehungsgeschichte der <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html">Java-Enums</a> sein. Kurz zusammengefasst:</p>
<blockquote><p><strong>JLD#3:</strong> So an enum is&#8230; a non-instantiable, memberless, final class with subclasses, members and instances?<br />
<strong>JLD#2:</strong> Yes!<br />
<strong>JLD#1:</strong> Precisely!<br />
<strong>JLD#3:</strong> But that&#8217;s just a plain old class!<br />
<strong>JLD#1:</strong> No, silly! It&#8217;s an <em>enum</em>!</p></blockquote>
<p>Java ist zum Teil schon sehr bescheuert&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/16/java-5-enums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmier-Tipps</title>
		<link>http://markus.ocrs.at/2009/01/12/programmier-tipps/</link>
		<comments>http://markus.ocrs.at/2009/01/12/programmier-tipps/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 17:50:20 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Software-Engineering]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=61</guid>
		<description><![CDATA[Ich bin auf einen Artikel von Wil Shipley gestoßen: Free Programming Tips are Worth Every Penny. Für diejenigen denen der Name nichts sagt: Wil Shipley ist der Autor einer sehr genialen Software (für Mac): Delicious Library &#8211; eine Software mit der ich bisher durchwegs zufrieden bin, und bei der der Preis für die Features mehr [...]]]></description>
			<content:encoded><![CDATA[<p>Ich bin auf einen Artikel von <a href="http://wilshipley.com/">Wil Shipley</a> gestoßen: <a href="http://wilshipley.com/blog/2005/02/free-programming-tips-are-worth-every.html">Free Programming Tips are Worth Every Penny</a>. Für diejenigen denen der Name nichts sagt: Wil Shipley ist der Autor einer sehr genialen Software (für Mac): <a href="http://www.delicious-monster.com/">Delicious Library</a> &#8211; eine Software mit der ich bisher durchwegs zufrieden bin, und bei der der Preis für die Features mehr als gerechtfertigt ist (insbesondere da es über <a href="http://www.oncampus.at/">Apple on Campus</a> einen Studentenrabatt gibt).</p>
<p>Wie auch immer, in dem oben erwähnten Artikel gibt er einige Tipps, wie man Software-Engineering betreiben sollte. In den meisten Fällen kann ich ihm bedenkenlos zustimmen. Jeder der irgendwie mit Programmieren zu tun hat sollte den Artikel lesen, er ist auch zum Teil recht unterhaltsam geschrieben. Dennoch will ich einige Teile davon hier herausnehmen und kommentieren&#8230;</p>
<blockquote><p>* The Way of the Code Samurai *</p>
<p>Now, I don&#8217;t actually know much about real samurai, but the basic thing I&#8217;ve heard is they stand and stare at each other for hours, and then suddenly BAM strike once and the other guy is down.</p>
<p>That&#8217;s how you should code.</p></blockquote>
<p>Ich finde das ist ein durchaus gelungener Vergleich. Es bedarf zwar ein bisschen einer Erklärung was er damit genau meint, aber ich muss zugeben, dass mich diese Formulierung durchaus amüsiert hat. Gemeint hat er damit:</p>
<blockquote><p>Think first. Think some more. Think about the whole problem. Think about a little part of the problem you&#8217;re going to start with. Think about the whole thing again, in relation to your idea on the starting point.</p></blockquote>
<p>Jetzt sollte der obige Vergleich klar sein. Viele mögen in diesem Fall durchaus anderer Meinung sein &#8211; insbesondere die ganze Agile Development Methodologie sieht ja vor das man einfach zum Programmieren anfangen sollte, und wenn etwas nicht passt kann man es ja ändern, weil Code-Änderungen billig sind. Das mag durchaus sein, aber es ist schon sehr sinnvoll sich zuerst genau zu überlegen was man denn eigentlich Programmieren will, sich einen Algorithmus zu überlegen und vor allem zu verstehen was man erreichen will und wie sich das mit dem Rest des Codes verträgt.</p>
<p>Nicht unwesentlich ist auch &#8211; wie auch in dem Artikel aufgeführt wird &#8211; dass man verschiedene Features zuerst in einem kleinen Test-Rahmen implementieren sollte, und erst dann in das eigentliche Projekt übernehmen soll &#8211; oder besser gleich nochmal neu schreiben.</p>
<blockquote><p>Write all your code &#8220;clean&#8221;, the first time you write it. Make classes for everything. Use enumerated types. Don&#8217;t take shortcuts. Don&#8217;t have any part of the code where you say, &#8220;Oh, yah, I just glossed over that for now.&#8221; You are NOT going to go back and fix it. Seriously, how often do you say to yourself, &#8220;I think I&#8217;ll dive into this messy code today and try to make it nice and pretty without adding any functionality?&#8221;</p></blockquote>
<p>Ich habe schon viel Zeit damit verbracht Code &#8220;zu reinigen&#8221; &#8211; zwar auch nur wenn ich neue Funktionalität hinzufügen will, aber oft ist es dabei dazu gekommen, dass ich zuerst grundlegende Funktionalitäten neu implementiert habe. Am Ende erreicht man dann zwar viel saubereren &#8211; und mitunter auch fehlerfreieren &#8211; Code, aber man denkt sich auch oft warum das nicht gleich so geschrieben wurde. In den meisten Fällen war es wenigstens nicht mein eigener Code, aber es gab durchaus auch Momente wo ich den eigenen Code gereinigt habe &#8211; oder in manchen Extremfällen gleich ganz neu geschrieben habe.</p>
<blockquote><p>Don&#8217;t gloss over anything. Write every line to be bulletproof. Write every method as if every other method was out to get your code and try to make it crash, and your job was to make sure it wasn&#8217;t going to happen in YOUR code. Assume the user is going to hit keys randomly. Assume the network is going to get disconnected. Assume the hardware will fail.</p></blockquote>
<p>Dazu kann ich eigentlich gar nichts mehr sagen. Amen.</p>
<blockquote><p>Less source code is better. This is almost always true. The exceptions to this are so rare that every time you think you&#8217;ve found one you should REALLY doubt yourself.</p></blockquote>
<p>Diese Aussage ist definitiv richtig. Durch Test-Driven-Development lassen sich zahlreiche Fällen davon ausschließen (weil man ja nur noch den Code schreibt den man wirklich braucht, und nicht auch noch jenen den man vielleicht mal brauchen könnte), aber grundsätzlich ist ein kurzer Code nie falsch.</p>
<p>Soviel zum Artikel. Aber auch die Kommentare dabei sind mitunter einer Erwähnung würdig:</p>
<blockquote><p>Thinking first, then doing, is #1. I find it applies to more and more in life. If one gets too finicky, one will surely end up a very sad, lonely Mr. Spock type-of-person, but in many ways this fascist dogma is very good, and extremely healthy &#8211; if you want to remain sanely in business for long.</p></blockquote>
<p>Ich lese gerade &#8220;Blink&#8221; von Malcolm Gladwell (wenn ich fertig bin wird es sicher auch wieder einen entsprechenden Artikel geben). In Kombination mit der obigen Aussage kam mir dabei der Gedanke, das man mit ausreichend Erfahrung nicht unbedingt immer wirklich viel nachdenken muss, bevor man mit dem Programmieren beginnt. Bei vielen Problemstellungen wird es einfach &#8220;BAM&#8221; machen, und man weiß genau was man wie tun muss. Wenn man dann noch darüber nachdenkt ist eher zu befürchten, dass es zu einer weniger idealen Lösung kommt.</p>
<p>Der Vergleich gilt durchaus auch beim Design von Software. Wenn man sich ein Design ansieht, und dabei der erste Eindruck &#8220;seltsam&#8221; (oder etwas äquivalentes) ist &#8211; und man bereits ein bisschen Erfahrung hat &#8211; dann ist durchaus anzunehmen, dass irgendetwas mit dem Design nicht stimmt.</p>
<blockquote><p>If Microsoft designed bridges I&#8217;d stay the fuck home.</p></blockquote>
<p>Dieser Kommentar kommt aus der Diskussion, ob Software Engineering wirklich Engineering ist oder nicht. Weil im &#8220;herkömmlichen Engineering&#8221; muss man wirklich von Anfang an alles bedenken und durchkonstruieren (wie beispielsweise bei einer Brücke), bevor man mit dem Bau beginnt, und dann kann man nichts mehr ändern, und bei der Software kann man auch bedenkenlos anfangen und immer wenn es notwendig ist entsprechende Änderungen durchführen. Dazu habe ich auch einen interessanten Artikel gefunden (Software-Engineering beim NASA Space-Shuttle Projekt &#8211; dort ist es wirklich Engineering), den ich bei Gelegenheit kommentieren möchte&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/12/programmier-tipps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development unter PowerPC</title>
		<link>http://markus.ocrs.at/2008/09/26/iphone-development/</link>
		<comments>http://markus.ocrs.at/2008/09/26/iphone-development/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 10:55:21 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/wordpress/?p=26</guid>
		<description><![CDATA[Es ist zwar mühsam das iPhone SDK auf einem PowerPC zu installieren, aber es geht. Dazu muss man das SDK herunterladen und die Daten aus dem Disk-Image herauskopieren. Sodann muss man in der Datei iPhone SDK.mpkg/iPhone SDK.dist ein paar Einträge ändern (zu der Datei kommt man über iPhone SDK.mpgk =&#62; Paketinhalt zeigen):
Die 3 Funktionen isIntel(), [...]]]></description>
			<content:encoded><![CDATA[<p>Es ist zwar mühsam das <a href="http://developer.apple.com/iphone/">iPhone SDK</a> auf einem PowerPC zu installieren, aber es geht. Dazu muss man das SDK herunterladen und die Daten aus dem Disk-Image herauskopieren. Sodann muss man in der Datei <tt>iPhone SDK.mpkg/iPhone SDK.dist</tt> ein paar Einträge ändern (zu der Datei kommt man über <tt>iPhone SDK.mpgk</tt> =&gt; Paketinhalt zeigen):</p>
<p>Die 3 Funktionen <tt>isIntel()</tt>, <tt>agreedToSLA()</tt> sowie <tt>SDKPresent()</tt> müssen so umgeschrieben werden, dass diese in jedem Fall <tt>true</tt> zurückgeben. Ist dies geschehen, so lässt sich das SDK mit der Datei <tt>iPhone SDK.mpkg</tt> installieren.</p>
<p>Nach der Installation funktioniert das SDK zwar prinzipiell, jedoch muss man noch den Simulator dazu bringen, den PowerPC als unterstützte Plattform zu akzeptieren. Dazu muss die Datei <tt>/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Specifications/iPhone Simulator Architectures.xcspec</tt> um die RealArchitectures <tt>ppc</tt> (=g3), <tt>ppc7400</tt> (=g4), <tt>ppc970</tt> (=g5) und/oder <tt>ppc64</tt> (=g5 64bit) erweitert werden. Zusätzlich müssen für diese Architekturen noch die entsprechenden Konfigurationsblöcke geschrieben oder aus der Datei <tt>/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX Architectures.xcspec</tt> übernommen werden. Dieser Vorgang wurde auch von <em>Tom Bradford</em> in seinem Blog beschrieben: <a href="http://www.tbradford.org/2008/03/iphone-sdk-beta-2-possible-ppc-fix.html">iPhone SDK Beta 2 PPC Fix</a>.</p>
<p>Ist dies erledigt, so kann man entsprechende Applikationen entwickeln und am Simulator testen. Sollen die Applikationen jedoch wirklich auf das iPhone übertragen werden, so müssen zuerst einmal entsprechend Münzen bei Apple eingeworfen werden (d.h. man muss sich für 99$ als iPhone Developer registrieren lassen). Danach kann man über den Apple-Developer-Account entsprechende Zertifikate für sich und seine Applikationen erstellen.</p>
<p>Wenn man den Anweisungen aus dem Developer-Portal folgt, so kann man mit den entsprechenden Zertifikaten theoretisch die Applikation erstellen und auf das iPhone übertragen. Allerdings schlägt aus irgendwelchen unerfindlichen Gründen dir Signaturprozess fehl. Dieses &#8220;Feature&#8221; lässt sich jedoch durch einen seltsamen Umweg lösen: das erzeugte Object File (ein Thin Binary) muss in ein Universal Binary umgewandelt werden. Das Universal Binary kann dann signiert werden, und anschließend wieder in ein Thin Binary rückgewandelt werden. Ich weiß weder wieso das funktioniert noch wie man auf sowas kommt, aber es ist in den Apple Diskussionsforen beschrieben worden: <a href="http://discussions.apple.com/message.jspa?messageID=7750868#7750868">iPhone SDK CodeSign Error</a>. Wenn man mit Projektverzeichnissen arbeitet, die Leerzeichen enthalten, so muss das oben erwähnte Script <a href="http://discussions.apple.com/message.jspa?messageID=7972661#7972661">wie im gleichen Thread erklärt</a> erweitert werden.</p>
<p>Anschließend sollte der Entwicklung, Übertragung und Veröffentlichung von iPhone Programmen nichts mehr im Wege stehen. Mir ist es jedenfalls auf diese Art gelungen eine kleine Anwendung auf mein iPhone zu übertragen.</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2008/09/26/iphone-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EJB Again</title>
		<link>http://markus.ocrs.at/2008/05/21/ejb-again/</link>
		<comments>http://markus.ocrs.at/2008/05/21/ejb-again/#comments</comments>
		<pubDate>Wed, 21 May 2008 11:30:33 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=155</guid>
		<description><![CDATA[Ich habe wieder einmal feststellen müssen, das man wahrhaftig viel Zeit mit Enterprise JavaBeans verscheißen kann. Ich hab mir nur eine kleine TestBean gebaut (inzwischen ist es schon ein bisschen mehr), die einen Kunden persistieren soll, bzw. aktualisieren falls dieser schon existiert. Der erste Versuch war wie folgt:
1234567891011121314public Long addCustomer&#40; String userName, String password, String [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe wieder einmal feststellen müssen, das man wahrhaftig viel Zeit mit Enterprise JavaBeans verscheißen kann. Ich hab mir nur eine kleine TestBean gebaut (inzwischen ist es schon ein bisschen mehr), die einen Kunden persistieren soll, bzw. aktualisieren falls dieser schon existiert. Der erste Versuch war wie folgt:</p>
<div class="codecolorer-container java 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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> addCustomer<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> userName, <span style="color: #003399;">String</span> password, <span style="color: #003399;">String</span> firstName, <span style="color: #003399;">String</span> lastName, <span style="color: #003399;">String</span> emailAddress <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Customer customer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Customer<span style="color: #009900;">&#40;</span> userName, password, firstName, lastName, emailAddress <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; entityManager.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span> customer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> EntityExistsException eee <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> sQuery <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select c from &quot;</span> <span style="color: #339933;">+</span> Customer.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; c where c.userName = :userName&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Query cQuery <span style="color: #339933;">=</span> entityManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span> sQuery <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cQuery.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;userName&quot;</span>, userName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; customer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Customer<span style="color: #009900;">&#41;</span> cQuery.<span style="color: #006633;">getSingleResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> customer.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Damit bekam ich aber dauernd eine Invalid Transaction Exception (ich hab mir nicht gemerkt wie die blöde Exception genau geheißen hat), wenn der Kunde bereits persistent ist.</p>
<p>Das Problem ist, dass eine EntityExistsException die aktuelle Transaction zum rollbacken markiert, und diese daher nicht mehr gültig ist. Wenn man das Ganze umdreht funktioniert’s auf wundersame Weise auf einmal:</p>
<div class="codecolorer-container java 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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> addCustomer<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> userName, <span style="color: #003399;">String</span> password, <span style="color: #003399;">String</span> firstName, <span style="color: #003399;">String</span> lastName, <span style="color: #003399;">String</span> emailAddress <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Customer customer<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> sQuery <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select c from &quot;</span> <span style="color: #339933;">+</span> Customer.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; c where c.userName = :userName&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Query cQuery <span style="color: #339933;">=</span> entityManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span> sQuery <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cQuery.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;userName&quot;</span>, userName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; customer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Customer<span style="color: #009900;">&#41;</span> cQuery.<span style="color: #006633;">getSingleResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* update fields*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; entityManager.<span style="color: #006633;">merge</span><span style="color: #009900;">&#40;</span> customer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span> NoResultException nre <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; customer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Customer<span style="color: #009900;">&#40;</span> userName, password, firstName, lastName, emailAddress <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; entityManager.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span> customer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> customer.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2008/05/21/ejb-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
