<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Get Set Games &#187; UIAlertView</title>
	<atom:link href="http://getsetgames.com/tag/uialertview/feed/" rel="self" type="application/rss+xml" />
	<link>http://getsetgames.com</link>
	<description></description>
	<lastBuildDate>Wed, 25 Aug 2010 16:11:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='getsetgames.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<link rel="http://api.friendfeed.com/2008/03#sup" xmlns="http://www.w3.org/2005/Atom" type="application/json" href="http://friendfeed.com/api/public-sup.json#5c973c50be"/>		<item>
		<title>How to Show an Alert with UIAlertView</title>
		<link>http://getsetgames.com/2009/12/02/iphonedev-advent-tip-2-how-to-show-an-alert-with-uialertview/</link>
		<comments>http://getsetgames.com/2009/12/02/iphonedev-advent-tip-2-how-to-show-an-alert-with-uialertview/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 21:14:04 +0000</pubDate>
		<dc:creator>Derek van Vliet</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[advent]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[UIAlertView]]></category>

		<guid isPermaLink="false">http://getsetgames.com/?p=683</guid>
		<description><![CDATA[Showing an alert message to the user isn&#8217;t just a handy interface lick, it&#8217;s also an invaluable debugging tool. Thankfully, this functionality is built into the iPhone SDK. To pop an alert with a title, message and OK button, we use the UIAlertView class like so: UIAlertView *alert = &#91;&#91;UIAlertView alloc&#93; initWithTitle: @&#34;Announcement&#34; message: @&#34;It [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://getsetgames.com/wp-content/uploads/2009/12/2.png"><img src="http://getsetgames.com/wp-content/uploads/2009/12/2-300x158.png" alt="2" title="2" width="300" height="158" class="alignright size-medium wp-image-684" /></a></p>
<p>Showing an alert message to the user isn&#8217;t just a handy interface lick, it&#8217;s also an invaluable debugging tool. Thankfully, this functionality is built into the iPhone SDK.</p>
<p>To pop an alert with a title, message and OK button, we use the UIAlertView class like so:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIAlertView <span style="color: #002200;">*</span>alert <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;Announcement&quot;</span>
			message<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;It turns out that you are playing Addicus!&quot;</span>
			delegate<span style="color: #002200;">:</span> <span style="color: #a61390;">nil</span>
			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>;
<span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>But what if you want to have more than one button on the alert and collect user input from it? Well that is pretty simple too. To do that, you first need to create a class that employs the UIAlertViewDelegate delegate like so:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> MyClass <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;UIAlertViewDelegate&gt;</pre></div></div>

<p>Then, in your class, you need to override the alertView method in order to receive input like so:</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><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>alertView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIAlertView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>alertView clickedButtonAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>buttonIndex <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>buttonIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;user pressed OK&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;user pressed Cancel&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Finally, we create the UIAlertView and pass in the delegate. Also note that we&#8217;ve labeled the Cancel button &#8220;Cancel&#8221; and added the &#8220;OK&#8221; button to the other button titles, which differs slightly from the above example.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIAlertView <span style="color: #002200;">*</span>alert <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;Announcement&quot;</span>
			message<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;It turns out that you are playing Addicus!&quot;</span>
			delegate<span style="color: #002200;">:</span> MY_DELEGATE
			cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cancel&quot;</span>
			otherButtonTitles<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;OK&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://getsetgames.com/2009/12/02/iphonedev-advent-tip-2-how-to-show-an-alert-with-uialertview/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:thumbnail url="http://getsetgames.com/wp-content/uploads/2009/12/2-150x150.png" />
		<media:content url="http://getsetgames.com/wp-content/uploads/2009/12/2.png" medium="image">
			<media:title type="html">2</media:title>
			<media:thumbnail url="http://getsetgames.com/wp-content/uploads/2009/12/2-150x150.png" />
		</media:content>
	</item>
	</channel>
</rss>
