<?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>iphone.mitchallen.com &#187; cheat sheet</title>
	<atom:link href="http://mitchallen.com/iphone/archives/category/cheat-sheet/feed" rel="self" type="application/rss+xml" />
	<link>http://mitchallen.com/iphone</link>
	<description>random notes on iPhone development</description>
	<lastBuildDate>Tue, 10 Aug 2010 20:36:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Wiring up a button</title>
		<link>http://mitchallen.com/iphone/archives/155</link>
		<comments>http://mitchallen.com/iphone/archives/155#comments</comments>
		<pubDate>Mon, 25 May 2009 13:53:24 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[cheat sheet]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[UIViewController]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=155</guid>
		<description><![CDATA[This is my first entry in a new category called &#8220;cheat sheet.&#8221; I&#8217;m trying to build an iPhone GUI for an application. Every time I want to do something simple &#8211; like add a button &#8211; I need to pull out my books on the subject and filter through several pages to remind myself how [...]]]></description>
			<content:encoded><![CDATA[<p>This is my first entry in a new category called &#8220;cheat sheet.&#8221;</p>
<p>I&#8217;m trying to build an iPhone GUI for an application.  Every time I want to do something simple &#8211; like add a button &#8211; I need to pull out my <a href="http://astore.amazon.com/iphone.mitchallen-20">books on the subject</a> and filter through several pages to remind myself how to do it.  So I&#8217;m putting the info here for myself and anyone else who finds the process unintuitive.</p>
<p>Let&#8217;s assume that you are adding a button to an existing UIViewController. The first thing that you need to do is add a handler for the button press to your controller class.</p>
<p>Your *.h file would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import  </span>
&nbsp;
<span style="color: #a61390;">@interface</span> HomeViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> configButtonPressed<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;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Your *.m (or *.mm) file would contain the corresponding method like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> configButtonPressed<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>
	NSLog<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;HomeViewController:configButtonPressed:sender&quot;</span> <span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p> </p>
<ol>
<li>Fire up <strong>Interface Builder</strong> by double-clicking on your *.xib file.  I&#8217;m assuming you already have a View set up.</li>
<li>I&#8217;m also assuming that  <strong>Tools / Inspector</strong> and <strong>Tools / Library</strong> show when you click on the View.</li>
<li>Under <strong>Library / Cocoa Touch Plugin / Inputs &amp; Values</strong> drag a <strong>Round Rect Button</strong> on to your View.</li>
<li>Double-click on the button and fill in a label.</li>
<li>Click elsewhere on the View to get out of label editing mode and single-click the button again.</li>
<li>Select the second tab in the <strong>Inspector</strong> (or press Apple-Key-2) &#8211; the title of the Inspector should say <strong>Button Connections</strong>.</li>
<li>Put your mouse over the circle to the right of event labeled <strong>Touch Up Inside</strong>.</li>
<li>Drag the mouse over the <strong>File&#8217;s Owner</strong> icon in the *.xib window.</li>
<li>When you release the mouse, select the method that you added to your controller class (in this example <strong>configButtonPressed</strong>).</li>
<li>Save the *.xib file, and select <strong>Build and Go</strong> to make sure you wired the button correctly.</li>
<li>In this example when you click the button it should log something to the <strong>Debugger Console</strong>.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/155/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
