<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>TEMPESTINI.NET &#187; iPhone Development</title>
	<atom:link href="http://tempestini.net/category/iphone-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://tempestini.net</link>
	<description>Observations in Software Development</description>
	<lastBuildDate>Mon, 21 May 2012 17:18:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='tempestini.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>TEMPESTINI.NET &#187; iPhone Development</title>
		<link>http://tempestini.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tempestini.net/osd.xml" title="TEMPESTINI.NET" />
	<atom:link rel='hub' href='http://tempestini.net/?pushpress=hub'/>
		<item>
		<title>Passing Values on the Tag Attribute</title>
		<link>http://tempestini.net/2009/05/31/passing-values-on-the-tag-attribute/</link>
		<comments>http://tempestini.net/2009/05/31/passing-values-on-the-tag-attribute/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 00:31:20 +0000</pubDate>
		<dc:creator>Rick Tempestini</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://tempestini.net/?p=300</guid>
		<description><![CDATA[I&#8217;m learning to develop in XCode for the iPhone.  Being a long time Microsoft developer I admittedly struggle with some of the most simple things in this new XCode/Objective-C world.  One of my recent struggles was when I  attempted to assign several controls in Interface Builder (or, IB for short) unique Tag attributes and then [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tempestini.net&#038;blog=662943&#038;post=300&#038;subd=vbasp&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m learning to develop in XCode for the iPhone.  Being a long time Microsoft developer I admittedly struggle with some of the most simple things in this new XCode/Objective-C world.  One of my recent struggles was when I  attempted to assign several controls in Interface Builder (or, IB for short) unique Tag attributes and then read them in the IBAction method.  I searched far and wide and finally found the answer.</p>
<p>In my scenario, I had several buttons in my View that I wanted to handle with a single method.  I needed to find a way to differentiate between them to find out which one the user clicked.</p>
<p><strong>Solution: </strong></p>
<p>In IB I created three buttons as shown below.  I then selected each one separately and assigned it a unique &#8216;Tag&#8217; attribute.  The &#8216;Tag&#8217; attribute is located on the &#8216;Button Attributes&#8217; tab of the Inspector.</p>
<p><img class="alignnone size-full wp-image-302" title="TagExample" src="http://vbasp.files.wordpress.com/2009/05/tagexample1.jpg" alt="TagExample" width="614" height="792" /></p>
<p>That part wasn&#8217;t much of a challenge.  What, unfortunately, was a challenge was getting this value from within the IBAction method.  First, the action method is declared in my ViewController.h file like any other IBAction method:</p>
<pre>#import <span style="color:#ff0000;">&lt;UIKit/UIKit.h&gt;</span>

<span style="color:#cc99ff;">@interface</span> ViewController : UIViewController {
}

- (<span style="color:#cc99ff;">IBAction</span>)push:(<span style="color:#cc99ff;">id</span>)sender;

<span style="color:#cc99ff;">@end</span></pre>
<p>Next, the important part.  I had to find a way to get the actual value in my push method.  After several unsuccessful variations of trying to call [sender tag] directly, I found the answer (shown in bold below):</p>
<pre>@implementation ViewController

- (<span style="color:#cc99ff;">IBAction</span>)push:(<span style="color:#cc99ff;">id</span>)sender
{
<strong> UIButton *btn = (UIButton *)sender;
 NSInteger tag = [btn tag];</strong>
 NSLog(<span style="color:#cc99ff;">@"Tag: %d"</span>, tag);</pre>
<p>The answer is actually very simple.  Since sender is a generic object type I had to cast it to a UIButton before I could get to the tag property.</p>
<p>Stay tuned.  At this rate there are many more of these quick samples on the way&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vbasp.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vbasp.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vbasp.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vbasp.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vbasp.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vbasp.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vbasp.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vbasp.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tempestini.net&#038;blog=662943&#038;post=300&#038;subd=vbasp&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tempestini.net/2009/05/31/passing-values-on-the-tag-attribute/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94258dc22f658263fcfe9c32b6c813a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rick Tempestini</media:title>
		</media:content>

		<media:content url="http://vbasp.files.wordpress.com/2009/05/tagexample1.jpg" medium="image">
			<media:title type="html">TagExample</media:title>
		</media:content>
	</item>
	</channel>
</rss>
