<?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>simra &#187; UIButton</title>
	<atom:link href="http://www.simra.ch/tag/uibutton/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simra.ch</link>
	<description>development &#38; design</description>
	<lastBuildDate>Fri, 26 Mar 2010 15:57:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>iPhone Tutorial 2 (Interface Builder &#8211; Downloader)</title>
		<link>http://www.simra.ch/2010/02/iphone-tutorial-2-interface-builder-downloader/</link>
		<comments>http://www.simra.ch/2010/02/iphone-tutorial-2-interface-builder-downloader/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 19:54:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[interface builder]]></category>
		<category><![CDATA[UIButton]]></category>
		<category><![CDATA[UITextField]]></category>
		<category><![CDATA[UITextView]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1134</guid>
		<description><![CDATA[In diesem Tutorial geht es darum ein einfaches iPhone-App zu erstellen, dass eine beliebige Url herunterläd und den Inhalt ausgibt. Zusätzlich wird der Interface Builder kurz vorgestellt.

Wenn die iPhone SDK bereits installiert wurde, erscheint das folgende Fenseter mit den iPhone Projekt Templates. Wir wählen das Letzte &#8220;Window-Based Application&#8221; und nennen das Projekt &#8220;downloader&#8221;.

Wenn wir unmittelbar [...]]]></description>
			<content:encoded><![CDATA[<p>In diesem Tutorial geht es darum ein einfaches iPhone-App zu erstellen, dass eine beliebige Url herunterläd und den Inhalt ausgibt. Zusätzlich wird der Interface Builder kurz vorgestellt.<br />
<span id="more-1134"></span><br />
Wenn die iPhone SDK bereits installiert wurde, erscheint das folgende Fenseter mit den iPhone Projekt Templates. Wir wählen das Letzte &#8220;Window-Based Application&#8221; und nennen das Projekt <strong>&#8220;downloader&#8221;</strong>.</p>
<p><img class="aligncenter size-full wp-image-1135" title="iphone-new-project-2" src="http://www.simra.ch/wordpress/../uploads/2010/02/iphone-new-project-2.png" alt="" width="450" height="332" /></p>
<p>Wenn wir unmittelbar nach dem Erstellen des Projekts auf <strong>&#8220;Build and Go&#8221;</strong> klicken erscheint ein leeres Fenster. Als nächstes werden wir ein kleines Formular mit Textbox, Button und Textarea kreieren.</p>
<p>Dazu öffnen wir die Datei MainWindow.xib (Mehr zur Bedeutung der Standard Dateien finden Sie <a title="iPhone SDK Standard Dateien" href="http://www.simra.ch/2010/02/iphone-sdk-standard-dateien/" target="_blank">hier</a>). Das ist die Ansicht (View), die als Erstes gestartet wird.</p>
<p>Wenn sich der Interface-Builder gestartet hat, fügen wir über die Library ein <strong>UITextField</strong>, ein <strong>UIButton</strong> und ein <strong>UITextView</strong> zum leeren Fenster hinzu. Dannach sollte das Fenster wie folgt aussehen.</p>
<p><img src="http://www.simra.ch/wordpress/../uploads/2010/02/tutorial-2-1.png" alt="" title="tutorial-2-1" width="200" height="313" class="aligncenter size-full wp-image-1157" /></p>
<p>Als nächstes müssen wir die Delegationen für diese drei Elemente (<strong>UITextField, UIButton und UITextView</strong>) definieren.<br />
Dies geschiet in der Header-Datei <strong>downloaderAppDelegate.h</strong>.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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> downloaderAppDelegate <span style="color: #002200;">:</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> &lt;UIApplicationDelegate&gt; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UIWindow <span style="color: #002200;">*</span>window;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Die Url-Eingabe</span><br />
&nbsp; &nbsp; IBOutlet UITextField <span style="color: #002200;">*</span> url;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Die Ausgabe </span><br />
&nbsp; &nbsp; IBOutlet UITextView <span style="color: #002200;">*</span> content;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// Unser Download-Button</span><br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>download<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;<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 />
<br />
<span style="color: #a61390;">@end</span></div></div>
<p><em>Die Funktion <strong>IBAction</strong> wird später der Click-Event des Download-Buttons.</em></p>
<p>Jetzt müssen wir die beiden deklarierten <strong>IBOutlet</strong> und unsere <strong>IBAction</strong> mit den Elementen verknüpfen. Dazu öffnen wir wieder die Datei <strong>MainWindow.xib</strong> und somit den Interface-Builder. Um ein Element zu verknüpfen kann der <strong>Connections Inspector</strong> verwendet werden oder es wird mit der rechten Maustaste auf das gewünschte Objekt geklickt (siehe folgende Abbildungen).</p>
<p><img src="http://www.simra.ch/wordpress/../uploads/2010/02/tutorial-2-2.png" alt="" title="tutorial-2-2" width="450" height="361" class="aligncenter size-full wp-image-1155" /><br />
<em>Rechtsklick auf das UITextField und im Menu rechts neben <strong>&#8220;New Referencing Outlet&#8221;</strong> auf den Kreis klicken und mit der Maus auf <strong>downloaderAppDelegate</strong> ziehen und Variable <strong>url</strong> auswählen.</em></p>
<p>Nun verknüpfen wir den Button mit der <strong>IBAction</strong>, damit wir später den Click-Event bekommen.</p>
<p><img src="http://www.simra.ch/wordpress/../uploads/2010/02/tutorial-2-3.png" alt="" title="tutorial-2-3" width="450" height="362" class="aligncenter size-full wp-image-1160" /><br />
<em>Rechtsklick auf den <strong>UIButton</strong> und im Menu rechts neben <strong>&#8220;Touch Up Inside&#8221;</strong> auf den Kreis klicken und mit der Maus auf <strong>downloaderAppDelegate</strong> ziehen und Variable <strong>download</strong> auswählen.</em></p>
<p>Jetzt brauchen wir noch das <strong>UITextView</strong> zu verknüpfen. Das geschieht gleich wie beim <strong>UITextField</strong>.<br />
<img src="http://www.simra.ch/wordpress/../uploads/2010/02/tutorial-2-4.png" alt="" title="tutorial-2-4" width="450" height="361" class="aligncenter size-full wp-image-1161" /></p>
<p>Wenn das getan ist und das Progamm immer noch startet, können wir mit dem eigentlichen Programmieren beginnen.<br />
Dazu öffnen wir die Datei <strong>downloaderAppDelegate.m</strong> und passen den Code wie folgt an.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><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;downloaderAppDelegate.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> downloaderAppDelegate<br />
<br />
<span style="color: #a61390;">@synthesize</span> window;<br />
<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; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Starttext </span><br />
&nbsp; &nbsp; content.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Enter a url and press <span style="color: #2400d9;">\&quot;</span>Download<span style="color: #2400d9;">\&quot;</span>&quot;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Url Vorschlag</span><br />
&nbsp; &nbsp; url.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.simra.ch/&quot;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <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: #11740a; font-style: italic;">//Click Event des Download Buttons</span><br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>download<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Statustext</span><br />
&nbsp; &nbsp; content.text<span style="color: #002200;">=</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;downloading...<span style="color: #2400d9;">\n</span>please wait...&quot;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Url anfordern</span><br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> <span style="color: #002200;">*</span>req<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> requestWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span style="color: #400080;">NSURL</span></a> URLWithString<span style="color: #002200;">:</span>url.text<span style="color: #002200;">&#93;</span><br />
&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; &nbsp; &nbsp; cachePolicy<span style="color: #002200;">:</span>NSURLRequestUseProtocolCachePolicy<br />
&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; &nbsp; &nbsp; timeoutInterval<span style="color: #002200;">:</span>30.0<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLResponse_Class/"><span style="color: #400080;">NSURLResponse</span></a> <span style="color: #002200;">*</span>res <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/"><span style="color: #400080;">NSError</span></a> <span style="color: #002200;">*</span>err <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/"><span style="color: #400080;">NSData</span></a> <span style="color: #002200;">*</span>dat <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a> sendSynchronousRequest<span style="color: #002200;">:</span> req returningResponse<span style="color: #002200;">:</span> <span style="color: #002200;">&amp;</span>res error<span style="color: #002200;">:</span> <span style="color: #002200;">&amp;</span>err<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>res<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span> str <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithData<span style="color: #002200;">:</span>dat encoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; content.text <span style="color: #002200;">=</span>str;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Vorgang fehlgeschlagen -&gt; Meldung ausgeben</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Url couldn't be downloaded...&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; UIAlertView <span style="color: #002200;">*</span>msg <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error&quot;</span> message<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Url couldn't be downloaded&quot;</span> delegate<span style="color: #002200;">:</span> self cancelButtonTitle<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Ok&quot;</span> otherButtonTitles<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>msg show<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>msg release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</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 />
<br />
<span style="color: #a61390;">@end</span></div></div>
<p>Das ganze Projekt kann <a href="http://www.simra.ch/uploads/downloads/iphone/downloader/iphone-downloader.zip">hier</a> heruntergeladen werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2010/02/iphone-tutorial-2-interface-builder-downloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

