<?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>Learn iPhone App Development with FourTen</title>
	<atom:link href="http://learn-iphone-app-development.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://learn-iphone-app-development.com</link>
	<description></description>
	<lastBuildDate>Wed, 29 Feb 2012 23:19:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='learn-iphone-app-development.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Learn iPhone App Development with FourTen</title>
		<link>http://learn-iphone-app-development.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://learn-iphone-app-development.com/osd.xml" title="Learn iPhone App Development with FourTen" />
	<atom:link rel='hub' href='http://learn-iphone-app-development.com/?pushpress=hub'/>
		<item>
		<title>Expired Provisioning Profiles &#8212; Why Won&#8217;t My App Run/Debug?</title>
		<link>http://learn-iphone-app-development.com/2011/03/08/expired-provisioning-profiles-why-wont-my-app-rundebug/</link>
		<comments>http://learn-iphone-app-development.com/2011/03/08/expired-provisioning-profiles-why-wont-my-app-rundebug/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 00:03:52 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[certificate]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[provisioning]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[technologies]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=108</guid>
		<description><![CDATA[This post answers the following questions: Why won&#8217;t my app run or debug? What do I do with &#8220;The application cannot be opened because the provisioning profile has expired?&#8221; I&#8217;m getting &#8220;The program being debugged is not being run&#8221; &#8212; &#8230; <a href="http://learn-iphone-app-development.com/2011/03/08/expired-provisioning-profiles-why-wont-my-app-rundebug/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=108&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>Why won&#8217;t my app run or debug?</em></li>
<li><em>What do I do with &#8220;The application cannot be opened because the provisioning profile has expired?&#8221;</em></li>
<li><em>I&#8217;m getting &#8220;The program being debugged is not being run&#8221; &#8212; help!</em></li>
<li><em>What does, &#8220;Error from Debugger : The program being debugged is not being run&#8221; mean?</em></li>
</ol>
<p>We were modifying an older application for a client today, and Xcode simply would not let us debug on our iPad.  Xcode was telling us, &#8220;&#8221;Error from Debugger : The program being debugged is not being run.&#8221;  Great.  Care to tell us why?</p>
<p>After looking around for a bit, we tried running the app on the device by pressing the springboard icon rather than Build &amp; Go from Xcode, and were confronted with a different error: &#8220;The application cannot be opened because the provisioning profile has expired.&#8221;  Ok, that&#8217;s a little more clear, but we&#8217;re still in Apple code signing hell, which any iPhone developer knows can eat up hours of time.</p>
<p>Uninstalling the app and re-installing did not help, Clean All Targets didn&#8217;t help, and adjusting the code signing on both the project and the active target did nothing &#8212; both were set to use our automatically provisioned profile.  We updated our automatically provisioned profile a few weeks ago to replace an expiring one, so I knew that the profile was valid.  But, I checked it out anyway, and saw a screen much like this:</p>
<p><img class="aligncenter" style="border:1px solid black;" title="Organizer with Expired Profile" src="http://learniphoneappdevelopment.files.wordpress.com/2011/03/20110308-1.png?w=640&h=480" alt="" width="640" height="480" /></p>
<p>This screen can be found by bringing up Organizer while your device is plugged in, and then clicking on your device.  What appears to have happened is that even though our new provisioning profile was downloaded by the development machine, and even though that profile was distributed to this iPad, the old profile remained and was being used by default.</p>
<p>Lame, but a quick solution: remove the profile with the X.  For good measure, we uninstalled the app from the iPad and Cleaned All Targets, and then Build and Run ran as it should.  I hope this helps (though by the time you&#8217;ve found this, you&#8217;ve probably already wasted at least half an hour trying to figure it out!).</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Jonathan Corbett</a> (President &amp; CEO, FourTen). Contact: <a href="mailto:jcorbett@fourtentech.com">jcorbett@fourtentech.com</a><a href="http://hostel-octogongastehaus-review.blogspot.com/">.</a></em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=108&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/03/08/expired-provisioning-profiles-why-wont-my-app-rundebug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/03/20110308-1.png" medium="image">
			<media:title type="html">Organizer with Expired Profile</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Data from Web Services — The Easy Way</title>
		<link>http://learn-iphone-app-development.com/2011/02/03/getting-data-from-web-services-%e2%80%94-the-easy-way/</link>
		<comments>http://learn-iphone-app-development.com/2011/02/03/getting-data-from-web-services-%e2%80%94-the-easy-way/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 15:39:32 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[stringwithcontentsofurl]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=18</guid>
		<description><![CDATA[This post answers the following questions: Do I need to use XML to transfer data from a Web service? How can I get data from PHP to my app? How can I send data to a script on a Web &#8230; <a href="http://learn-iphone-app-development.com/2011/02/03/getting-data-from-web-services-%e2%80%94-the-easy-way/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=18&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>Do I need to use XML to transfer data from a Web service?</em></li>
<li><em>How can I get data from PHP to my app?</em></li>
<li><em>How can I send data to a script on a Web server &#8212; without XML?</em></li>
</ol>
<p>Many times we get project specs from our clients that call for XML to transfer data between a Web service of some sort (be it PHP, .NET, or something else), and most of the time, the amount and complexity of data being returned is minimal. When this is the case, we generally advise against using the beloved XML for the transfer.</p>
<p>&#8220;That&#8217;s blasphemy,&#8221; you say? No, it&#8217;s actually a compliment to XML. As it is able to handle large and complex data operations, it simply contains a bunch of &#8220;stuff&#8221; that we don&#8217;t need, and implementing a parser takes development time, which costs you money, and processor time, which costs your app&#8217;s response time.</p>
<p>The most common data transferred back and forth is a user account. Username, password, e-mail, and maybe a few other fields specific to the application. We could put those fields in an XML file and POST it back to a Web service:</p>
<p><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;<br />
&lt;Register&gt;<br />
&lt;user&gt;410Technologies&lt;/user&gt;<br />
&lt;pass&gt;********&lt;/pass&gt;<br />
&lt;email&gt;sales@fourtentech.com&lt;/email&gt;<br />
&lt;/Register&gt;</code></p>
<p>&#8230;and waste all the overhead required to build and store that string (both CPU/memory overhead and coding time overhead) and transmit it over the air, or we could simply call the Web service via GET, like so:</p>
<p><code>?user=410Technologies&amp;pass=********&amp;email=sales%40fourtentech%20com</code></p>
<p>Note that neither method is more or less secure: both can be done over HTTPS, if you&#8217;d like.  Similarly, when we get data back, we can use a similar technique. A typical login command might return the user&#8217;s first name (to welcome them, of course), an account status, and an account balance. We could do that with XML:</p>
<p><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;<br />
&lt;Login&gt;<br />
&lt;firstname&gt;Max&lt;/firstname&gt;<br />
&lt;status&gt;1&lt;/status&gt;<br />
&lt;balance&gt;$4.10&lt;/balance&gt;<br />
&lt;/Login&gt;</code></p>
<p>&#8230;or we can pick a delimiter and send the three fields without any fancy encoding. If you&#8217;re returning a field that was input by a user on an iPhone, the <em>tab</em> character (&#8216;\r&#8217;) makes a great delimiter, since there&#8217;s no way a user can type a tab using the iPhone. We code our Web service to return a string that looks like this:</p>
<p><code>Max\r1\r\$4.10</code></p>
<p>&#8230;and can load that into an array quickly and easily using the <em>componentsSeparatedByString:</em> function:</p>
<p><code>NSArray *user = [[NSArray alloc] initWithArray:[[NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://clients.fourtentech.com/sample/web/service.aspx"]] componentsSeparatedByString:@"\r"]]</code></p>
<p>&#8230;saving about 80% of the bandwidth, avoiding implementing a resource-intensive parser, and remembering to release our object when we&#8217;re done, of course.</p>
<p>If you&#8217;re developing large, complex data transfers, or transfers that may become that way, XML is your friend. When that&#8217;s not the case, we keep it simple and respect that on a tiny device with an often-slow connection, we should conserve as many resources as possible, as well as conserving our client&#8217;s financial resources whenever possible as well (we&#8217;d much rather sell you useful features and add-ons rather than &#8220;technicalities&#8221; like unnecessary XML implementations!).</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Max Whitman</a> (Lead Developer, FourTen). Contact: <a href="mailto:mwhitman@fourtentech.com">mwhitman@fourtentech.com</a>.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=18&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/02/03/getting-data-from-web-services-%e2%80%94-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>
	</item>
		<item>
		<title>Tables, Part III — Re-Ordering / Moving Cells and &#8220;Swipe to Delete!&#8221;</title>
		<link>http://learn-iphone-app-development.com/2011/01/31/tables-part-iii-%e2%80%94-re-ordering-moving-cells-and-swipe-to-delete/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/31/tables-part-iii-%e2%80%94-re-ordering-moving-cells-and-swipe-to-delete/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 10:52:10 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[cell]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[modify]]></category>
		<category><![CDATA[row]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[swipe]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uitableview]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=16</guid>
		<description><![CDATA[This post answers the following questions: How do I add re-order grips to my UITableViewCells? What do I do to allow users to remove cells from a UITableView? How can I implement swipe-to-delete? In Part II, we covered adding some &#8230; <a href="http://learn-iphone-app-development.com/2011/01/31/tables-part-iii-%e2%80%94-re-ordering-moving-cells-and-swipe-to-delete/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=16&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How do I add re-order grips to my UITableViewCells?</em></li>
<li><em>What do I do to allow users to remove cells from a UITableView?</em></li>
<li><em>How can I implement swipe-to-delete?</em></li>
</ol>
<p>In Part II, we covered adding some custom elements to your tables.  If you want to allow users to edit the contents of a cell, a common way of doing that is, once the user pushes an &#8220;Edit&#8221; button, to simply add a UITextField to your cell in the place of where you normally put, say, a UILabel.  The code from Part II should be able to get you through this.</p>
<p>But!  The UITableView offers some cool built-in features for moving and deleting cells that will give your app a more consistent &#8220;iPhone feel&#8221; than if you were to custom-implement them yourself, and may save you some time as well.</p>
<p>Starting with our code from the previous tutorial, we&#8217;re going to add a member variable to our view controller class header:</p>
<p><code>NSMutableArray *aCellText;</code></p>
<p>&#8230;and in our <em>viewDidLoad:</em> function, we&#8217;ll initialize the array with three objects:</p>
<p><code>aCellText = [[NSMutableArray alloc] initWithObjects:@"For mobile application", @"development, visit:", @"www.fourtentech.com", nil];</code></p>
<p>&#8230;and don&#8217;t forget to release the array when you&#8217;re done with it.  Then, in <em>cellForRowAtIndexPath:, </em>change this line:</p>
<p><code>l.text = [NSString stringWithFormat:@"cell %i", indexPath.row];</code></p>
<p>&#8230;to this one:</p>
<p><code>l.text = [aCellText objectAtIndex:indexPath.row];</code></p>
<p>Lastly, comment out the UIButton immediately below the line we just added, Build &amp; Go, and you should see something like this:</p>
<p><img class="aligncenter size-full wp-image-120" title="Our New UITableView from an Array" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110131-1.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>Our table&#8217;s contents is now dynamically generated from an array.  Now that we have some dynamic content, we can begin to edit it.  Add the following line to your <em>viewDidLoad:</em> function:</p>
<p><code>tvMain.editing = YES;</code></p>
<p>&#8230;as well as these two delegate methods:</p>
<p><code>- (BOOL)tableView:(UItableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {<br />
  return YES;<br />
}</p>
<p>- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {<br />
  NSObject *o = [aCellText objectAtIndex:sourceIndexPath.row];</p>
<p>  if(destinationIndexPath.row &gt; sourceIndexPath.row) //moving a row down<br />
    for(int x = destinationIndexPath.row; x &gt; sourceIndexPath.row; x--)<br />
      [aCellText replaceObjectAtIndex:x-1 withObject:[aCellText objectAtIndex:x]];<br />
  else //moving a row up<br />
    for(int x = destinationIndexPath.row; x &lt; sourceIndexPath.row; x++)<br />
      [aCellText replaceObjectAtIndex:x+1 withObject:[aCellText objectAtIndex:x]];</p>
<p>  [aCellText replaceObjectAtIndex:destinationIndexPath.row withObject:o];</p>
<p>  [tvMain reloadData];<br />
}</code></p>
<p>&#8230;and you should get the following after Bulid &amp; Go:</p>
<p><img class="aligncenter size-full wp-image-121" title="Re-order Grips and Delete Button" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110131-2.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>We&#8217;ve done a lot here &#8212; let&#8217;s take a step back.  The first thing we did was to turn on &#8220;editing mode&#8221; on the UITableView.  Normally, you wouldn&#8217;t do this in <em>viewDidLoad:, </em>but rather as a response to a user button press &#8212; though for tutorial purposes, this works.</p>
<p>We then added two delegate methods, the first of which is self-explanatory and needs no further commentary, but the second of which is more important.  When a user drags a cell from one position to the other using the reorder grips shown in the image, the UI updates, but you also need to update your data storage (in this case, an NSMutableArray) to reflect the change.  The code here detects if you&#8217;re trying to move a cell upwards or downwards, and then shifts all the cells between your original position and the desired position up or down to accommodate the change.  We then reload the table data to ensure that the view contiunes to display properly.</p>
<p>This also provides you a button to delete a cell, but 1) we haven&#8217;t yet implemented the code to handle the data store change on deletion, and 2) swipe to delete is way cooler than showing a delete button on every cell.  We&#8217;ll do both below.</p>
<p>Start by commenting out the <em>tvMain.editing</em> line that we put in earlier to get rid of the grips and delete buttons.  We&#8217;re then going to let the UITableView know that the number of rows may actually change by updating the contents of <em>numberOfRowsInSection: </em>to read:</p>
<p><code>return [aCellText count];</code></p>
<p>Then, we&#8217;re going to implement the following delegate method:</p>
<p><code>- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {<br />
  if(editingStyle == UITableViewCellEditingStyleDelete) {<br />
    [aCellText removeObjectAtIndex:indexPath.row];<br />
    [tvMain reloadData];<br />
  }<br />
}</code></p>
<p>When this delegate method is defined, the iPhone will allow swipe-to-delete with no further action necessary!  A rebuild and a swipe on the middle row will get us:</p>
<p><img class="aligncenter size-full wp-image-122" title="Swipe to Delete" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110131-3.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>This is the last of a three-part series on the UITableView &#8212; we hope it&#8217;s been useful!</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Andre Chambers</a> (Chief Technology Officer, FourTen). Contact: <a href="mailto:achambers@fourtentech.com">achambers@fourtentech.com</a>.</em></p>
<div id="_mcePaste">﻿</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=16&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/31/tables-part-iii-%e2%80%94-re-ordering-moving-cells-and-swipe-to-delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110131-1.png" medium="image">
			<media:title type="html">Our New UITableView from an Array</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110131-2.png" medium="image">
			<media:title type="html">Re-order Grips and Delete Button</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110131-3.png" medium="image">
			<media:title type="html">Swipe to Delete</media:title>
		</media:content>
	</item>
		<item>
		<title>Tables, Part II — Customizations (&#8220;Putting Stuff In Your Cells&#8221;)</title>
		<link>http://learn-iphone-app-development.com/2011/01/27/tables-part-ii-%e2%80%94-customizations-putting-stuff-in-your-cells/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/27/tables-part-ii-%e2%80%94-customizations-putting-stuff-in-your-cells/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 21:36:48 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[cell]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[inside]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uibutton]]></category>
		<category><![CDATA[uiimage]]></category>
		<category><![CDATA[uiimageview]]></category>
		<category><![CDATA[uilabel]]></category>
		<category><![CDATA[uitableview]]></category>
		<category><![CDATA[uitableviewcell]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=14</guid>
		<description><![CDATA[This post answers the following questions: How do I put stuff in my table? What do I do to add images to a UITableView / UITableViewCell? Can I put a button inside a table cell? The UITableViewCell comes with many &#8230; <a href="http://learn-iphone-app-development.com/2011/01/27/tables-part-ii-%e2%80%94-customizations-putting-stuff-in-your-cells/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=14&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How do I put stuff in my table?</em></li>
<li><em>What do I do to add images to a UITableView / UITableViewCell?</em></li>
<li><em>Can I put a button inside a table cell?</em></li>
</ol>
<p>The UITableViewCell comes with many ways to format the content within them.  But really, I don&#8217;t particularly care for using them.  Since you can simply add any UIView subclass as a subview of a UITableViewCell, I feel that using the built-in cell formatting techniques are limiting (with the exception of editable cells, which we&#8217;ll discuss in the next post), and most of our clients want their tables to do &#8220;moar.&#8221;</p>
<p>Start by creating a project with a UITableView just as we did in the previous tutorial, except make this one a &#8220;plain&#8221; table instead of a grouped table.  Set the number of sections to 1, the number of rows per section to 3, and the height of every row to be 75.0.  Also, add a 57x57px .png file to the project named &#8220;fourtentech.png&#8221; &#8212; any .png will do. </p>
<p>We&#8217;re going to adjust our <em>cellForRowAtIndexPath: </em>function to look like this:</p>
<p><code> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {<br />
 UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 75) reuseIdentifier:@"thecell"] autorelease];<br />
 cell.backgroundColor = [UIColor whiteColor];<br />
 <br />
 UIImageView *i = [[[UIImageView alloc] initWithFrame:CGRectMake(11, 11, 57, 57)] autorelease];<br />
 i.image = [UIImage imageNamed:@"fourtentech.png"];<br />
 [cell addSubview:i];<br />
 <br />
 UILabel *l = [[[UILabel alloc] initWithFrame:CGRectMake(65, 11, 229, 24)] autorelease];<br />
 l.text = [NSString stringWithFormat:@"cell %i of section %i",indexPath.row,indexPath.section];<br />
 l.font = [UIFont boldSystemFontOfSize:18];<br />
 [cell addSubview:l];<br />
 <br />
 UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];<br />
 b.frame = CGRectMake(250, 10, 60, 55);<br />
 [b addTarget:self action:@selector(dontTouchMe:) forControlEvents:UIControlEventTouchUpInside];<br />
 [b setTitle:@"Press Me!" forState:UIControlStateNormal];<br />
 b.buttonType = UIButtonTypeRoundRect;<br />
 b.tag = indexPath.row;<br />
 [cell addSubview:b];<br />
 <br />
 return cell;<br />
}</code></p>
<p>Build and Run, and you should now have:</p>
<p><img class="aligncenter size-full wp-image-113" style="border:1px solid black;" title="Table With &quot;Stuff&quot; -- An Image, a Label, and a Button" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110127-1.png?w=584" alt=""   /></p>
<p>We&#8217;ve added to the UITableViewCell an image, a label, and a button.  The frame specified in the CGRectMake is relative to the UITableViewCell (as it would have to be &#8212; otherwise your cell content wouldn&#8217;t move when the table did!).  Also, the frame that you give to the UITableViewCell, in this and many circumstances, doesn&#8217;t even need to be exact.  If it&#8217;s too small, your subviews can exceed the bounds of the cell (up to the height of the cell specified by the UITableView), and if it&#8217;s too big, it will be clipped by the UITableView.  In other words, if some of your cells are 40px high and others are 50px high, just set the UITableViewCell height to be 50px and don&#8217;t worry about it &#8212; everything will display just fine.</p>
<p>The only truly interesting thing about the above code is tagging the button.  The problem we&#8217;d encounter without tags is that when the button is pressed, our <em>dontTouchMe: </em>event handler would have no idea which of the three buttons was pressed.  We could set each button to have a different title and have our event handler check which title the event-sending button has, but maybe we want all the buttons to have the same title.  Tagging allows us to assign an integer to the button for later reference, and is completely transparent to the user.  Since we only have one section, we simply need to know the row number.</p>
<p>Create your <em>dontTouchMe: </em>function like the one below:</p>
<p><code>- (void)dontTouchMe:(id)sender {<br />
 NSLog(@"Touched Button %i",((UIButton *)sender).tag);<br />
}</code></p>
<p>&#8230;which will log to console which button was pressed.  Build &amp; Debug in Xcode, and push Command-Shift-R to bring up the console.  Then, when pressing a button (the first button, for example), you&#8217;ll see output:</p>
<p><img class="aligncenter" style="border:1px solid black;" title="Console Output" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110127-2.png?w=640&h=480" alt="" width="640" height="480" /></p>
<p>Note that touching the button and touching the rest of the cell are now completely different events, and can be coded to do completely different things.</p>
<p>This is a three-part series on the UITableView &#8212; please check back for more if you&#8217;re looking to go deeper.</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Andre Chambers</a> (Chief Technology Officer, FourTen). Contact: <a href="mailto:achambers@fourtentech.com">achambers@fourtentech.com</a>.</em></p>
<div id="_mcePaste">﻿</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=14&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/27/tables-part-ii-%e2%80%94-customizations-putting-stuff-in-your-cells/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110127-1.png" medium="image">
			<media:title type="html">Table With &#34;Stuff&#34; -- An Image, a Label, and a Button</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110127-2.png" medium="image">
			<media:title type="html">Console Output</media:title>
		</media:content>
	</item>
		<item>
		<title>Tables, Part I — How To Use Basic UITableViews</title>
		<link>http://learn-iphone-app-development.com/2011/01/22/tables-part-i-%e2%80%94-how-to-use-basic-uitableviews/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/22/tables-part-i-%e2%80%94-how-to-use-basic-uitableviews/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 11:47:21 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[cell]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[indexpath]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[row]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[sections]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uitableview]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=12</guid>
		<description><![CDATA[This post answers the following questions: How do I implement a basic table (UITableView) in my iPhone app? What do I do to respond when a user presses a table cell? I need to customize the contents of a UITableViewCell &#8230; <a href="http://learn-iphone-app-development.com/2011/01/22/tables-part-i-%e2%80%94-how-to-use-basic-uitableviews/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=12&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How do I implement a basic table (UITableView) in my iPhone app?</em></li>
<li><em>What do I do to respond when a user presses a table cell?</em></li>
<li><em>I need to customize the contents of a UITableViewCell &#8212; help?!</em></li>
</ol>
<p>The UITableView is one of the most well-recognized of the built-in components for iPhone.  There are two main styles of table: grouped and plain.  Grouped tables are typically used to show small amounts of data in a pretty, orderly layout.  Plain tables are better suited to larger datasets because of more efficient use of space and the ability to add an index on the right side to jump to a letter.  They are also better suited to completely custom cells.</p>
<table>
<tbody>
<tr>
<td align="center"> <img class="aligncenter" style="border:1px solid black;" title="Grouped Table" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-1.png?w=288&h=432" alt="" width="288" height="432" /><br />
Grouped Table</td>
<td align="center"> <img class="aligncenter" style="border:1px solid black;" title="Plain Table" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-2.png?w=288&h=432" alt="" width="288" height="432" /><br />
Plain Table</td>
</tr>
</tbody>
</table>
<p>We&#8217;ll start with the grouped table in Part I.  Either drag a UITableView onto your view in Interface Builder (IB) and select Grouped from View Attributes (press Command-1 if you don&#8217;t see it), or you can put it into your app via code:</p>
<p><code>UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStyleGrouped];<br />
tv.delegate = self;<br />
tv.dataSource = self;</code></p>
<p>If you add your table via code, don&#8217;t forget to release the object when you&#8217;re done with it.  If you add your UITableView using IB, you&#8217;ll need to create an outlet in code and set the delegate and data source in IB:</p>
<p><code>IBOutlet UITableView *tv;</code></p>
<p>&#8230;then right drag from File&#8217;s Owner in IB to the Web view to set the outlet, and right drag the reverse direction to set the delegate and data source.  What this does is it tells the SDK that the class that&#8217;s going to handle populating the table as well as dealing with table events is the current one.  Should this be a default?  Of course, but it&#8217;s not.  You&#8217;ll also need to designate your class as conforming to the relevant protocols.  In your .h, immediately after it says <em>UIViewController</em> (before the brace), add in <em>&lt;UITableViewDelegate,UITableViewDataSource&gt;</em></p>
<p>You&#8217;ve now got the basics down, but table views require five functions to be implemented.  The first we&#8217;ll implement as follows:</p>
<p><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {<br />
  return 2;<br />
}</code></p>
<p>So far, not to difficult.  In fact, I&#8217;m not sure this one needs any further explanation.  Moving along to our second:</p>
<p><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {<br />
  if(section == 0)<br />
    return 2;</code></p>
<p>  return 3;<br />
}</p>
<p>Also relatively straight forward.  The first section will have 2 rows, while all other sections will have 3.  Often times, you&#8217;ll be populating tables out of arrays, and so you&#8217;ll be returning <em>[array count]</em> instead of a constant.  Continuing&#8230;</p>
<p><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {<br />
  if(indexPath.section == 0 &amp;&amp; indexPath.row == 0)<br />
    return 75.0;</span></p>
<p>  return 50.0;<br />
}</code></p>
<p>The height in pixels for a given row.    Rows are identified by an indexPath, which is an object that has two relevant member variables: a section number and a row number.  The effect of the above code is that the first cell in the first section (numbering starts at 0, of course) will be 50% larger than all other rows.</p>
<p>Next is the most important: the code that generates the contents of your cells.  Each cell in your table is a UITableViewCell object, which in turn is a UIView object.  This means that you can simply add other objects as subviews of it:</p>
<p><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {<br />
  UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,300,75) reuseIdentifier:@"thecell"] autorelease];<br />
  cell.backgroundColor = [UIColor whiteColor];</p>
<p>  UILabel *l = [[[UILabel alloc] initWithFrame:CGRectMake(18,11,229,24)] autorelease];<br />
  l.text = [NSString stringWithFormat:@"cell %i of section %i",indexPath.row,indexPath.section];<br />
  [cell addSubview:l];</p>
<p>  return cell;<br />
}</code></p>
<p>The last thing required is code to handle what happens when a user touches a cell.  This code is required, even if you want to take no action (simply deselect the row and return).</p>
<p><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {<br />
  [tableView deselectRowAtIndexPath:indexPath animated:YES];<br />
}</code></p>
<p>Before you return, you&#8217;re free to check your <em>indexPath.section </em>and <em>indexPath.row </em>and take an action before deselection.  Deselection is required, and failure to do so may result in App Store rejection.  You now should get a table that looks like this:</p>
<p><a href="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-3.png"><img class="aligncenter size-full wp-image-101" title="Finished Grouped Table" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-3.png?w=584" alt=""   /></a></p>
<p>This is a three-part series on the UITableView &#8212; please check back for more if you&#8217;re looking to go deeper.</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Andre Chambers</a> (Chief Technology Officer, FourTen). Contact: <a href="mailto:achambers@fourtentech.com">achambers@fourtentech.com</a>.</em></p>
<div id="_mcePaste" class="mcePaste" style="position:absolute;width:1px;height:1px;overflow:hidden;top:0;left:-10000px;">﻿</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=12&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/22/tables-part-i-%e2%80%94-how-to-use-basic-uitableviews/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-1.png" medium="image">
			<media:title type="html">Grouped Table</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-2.png" medium="image">
			<media:title type="html">Plain Table</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110122-3.png" medium="image">
			<media:title type="html">Finished Grouped Table</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Web Content to Your App (UIWebView), Part IV — Is There Internet?</title>
		<link>http://learn-iphone-app-development.com/2011/01/15/adding-web-content-to-your-app-uiwebview-part-iv-%e2%80%94-is-there-internet/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/15/adding-web-content-to-your-app-uiwebview-part-iv-%e2%80%94-is-there-internet/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 12:08:54 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uiwebview]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webview]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=10</guid>
		<description><![CDATA[This post answers the following questions: How can I check if the device is connected to the Internet? What do I do to make sure my app doesn&#8217;t crash when I access Internet resources? If your application uses the Internet, &#8230; <a href="http://learn-iphone-app-development.com/2011/01/15/adding-web-content-to-your-app-uiwebview-part-iv-%e2%80%94-is-there-internet/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=10&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How can I check if the device is connected to the Internet?</em></li>
<li><em>What do I do to make sure my app doesn&#8217;t crash when I access Internet resources?</em></li>
</ol>
<p>If your application uses the Internet, but crashes if the user is not connected, Apple may reject your app upon App Store submission.  It&#8217;s therefore your responsibility to check to make sure Internet resources are available before you attempt to use them.  Unfortunately, there&#8217;s not a simple application variable or function to accomplish this check.</p>
<p>There are many ways of doing this out there, and our method is a little bit different.  It leverages the tools we learned in the previous 3 parts to this tutorial, presents the user with a clean, &#8220;Checking for Internet&#8230;&#8221; message, and leaves us with a more stable app.</p>
<p>Create a UIWebView as we did in the past three posts, and then add a boolean member variable and two more functions &#8212; in your .h:</p>
<p><code>BOOL internetOK;<br />
...<br />
- (void)tryInternet;<br />
- (void)verifyInternet;</code></p>
<p>&#8230;and your .m:</p>
<p><code>- (void)tryInternet {<br />
  internetOK = NO;<br />
  [wWw stringByEvaluatingJavaScriptFromString:@"window.location='http://www.fourtentech.com/';"];<br />
}</code></p>
<p><code>- (void)verifyInternet {<br />
  if(!internetOK) {<br />
    // no Internet access -- display error or take other action<br />
  }<br />
}</code></p>
<p>We&#8217;ll also need to include a new UIWebViewDelegate method:</p>
<p><code>- (void)webViewDidFinishLoad:(UIWebView *)webView {<br />
  internetOK = YES;<br />
}</code></p>
<p>What we&#8217;ve got here is a &#8220;check&#8221; function that sets our &#8220;Internet is OK&#8221; flag to <em>NO</em> and then tries to load a page.  If the page loads, <em>webViewDidFinishLoad:</em> is called and our flag is set to <em>YES</em>.  After a certain number of seconds (a timeout), we&#8217;ll call <em>verifyInternet </em>to see if our flag is set to <em>YES</em>, and if not, we know there&#8217;s been a failure.</p>
<p>To make this happen, present the user with a UIWebView with a message that you&#8217;re checking for Internet access (you can also do this with a hidden UIWebView and do it in the background!).  Here&#8217;s one we used in <a href="http://www.fourtentech.com/software/iphone/">our own iPhone app</a>:</p>
<p><code>[wWw loadHTMLString:@"&lt;body bgcolor='#DDDDDD'&gt;&lt;font face='Helvetica'&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color='#3080A0'&gt;&lt;center&gt;&lt;b&gt;Connecting to FourTen's server...&lt;/b&gt;&lt;center&gt;&lt;/font&gt;&lt;/font&gt;&lt;/body&gt;" baseURL:nil];</code></p>
<p>Then set our two functions to run:</p>
<p><code>[self performSelector:@selector(tryInternet) withObject:nil afterDelay:1.0];<br />
[self performSelector:@selector(verifyInternet) withObject:nil afterDelay:15.0];</code></p>
<p>The first one we run after 1 second, because if you try to run it simultaneously with loading the HTML string, it won&#8217;t work.  The second one we run after 15 seconds, making our timeout 14 seconds.  You can choose to wait more or less time.  After calling the first, <em>internetOK</em> will only be <em>YES</em> if Internet is detected.</p>
<p>This is the end of a four-part series on the UIWebView &#8212; we hope it&#8217;s been useful!</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Jonathan Corbett</a> (President &amp; CEO, FourTen). Contact: <a href="mailto:jcorbett@fourtentech.com">jcorbett@fourtentech.com</a>.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=10&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/15/adding-web-content-to-your-app-uiwebview-part-iv-%e2%80%94-is-there-internet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Web Content to Your App (UIWebView), Part III — Sending Messages</title>
		<link>http://learn-iphone-app-development.com/2011/01/12/adding-web-content-to-your-app-uiwebview-part-iii-%e2%80%94-sending-messages/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/12/adding-web-content-to-your-app-uiwebview-part-iii-%e2%80%94-sending-messages/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:58:27 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[info]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[send]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uiwebview]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webview]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=8</guid>
		<description><![CDATA[This post answers the following questions: How can I send a message from a UIWebView to my class? How can I take an action based on an event in a UIWebView? In the last post, we discussed creating navigation for &#8230; <a href="http://learn-iphone-app-development.com/2011/01/12/adding-web-content-to-your-app-uiwebview-part-iii-%e2%80%94-sending-messages/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=8&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How can I send a message from a UIWebView to my class</em><em>?</em></li>
<li><em>How can I take an action based on an event in a UIWebView?</em></li>
</ol>
<p>In the last post, we discussed creating navigation for a UIWebView, and used the <em>stringByEvaluatingJavaScriptFromString: </em>function as well as the <em>shouldStartLoadWithRequest: </em>delegate method.  In this post, we&#8217;re going to use both of those functions to get messages <em>from </em>the UIWebView to your Objective-C code.</p>
<p>The first way to get a message from your UIWebView is asynchronous.  All one must do is query the DOM using JavaScript.  Let&#8217;s say you had the following in your HTML:</p>
<p><code>&lt;input id="fourten" /&gt;</code></p>
<p>&#8230;and you wanted to find out what a user had typed in this text box.  All one would need to return the contents of the text box is:</p>
<p><code>[wWw stringByEvaluatingJavaScriptFromString:@"document.getElementById('fourten').value;"];</code></p>
<p>This is great if you just need to check the present value of something.  If you want to know when a user takes an action within the UIWebView, you&#8217;ll need a little bit more than this; otherwise, you&#8217;d be polling the UIWebView constantly.  We can accomplish this using the other function we talked about last week.</p>
<p>Set up your UIWebView, and load in the following HTML:</p>
<p><code>&lt;form action="http://message/"&gt;Tell me something: &lt;input id="fourten" /&gt;&lt;br /&gt;&lt;input type="submit" value="Go!" /&gt;&lt;/form&gt;</code></p>
<p>This naturally presents a text box and a submit button, and when the submit button is pressed, the data is sent to <em>http://message/, </em>a fictitious address.  But, before the data can be sent, the iPhone platform will consult <em>shouldStartLoadWithRequest:</em> to find out if we should proceed with that page load.  Instead, we&#8217;ll hijack that form submission and run our own code:</p>
<p><code>- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request {<br />
  if([[request.URL absoluteString] isEqualToString:@"http://message/"]) {<br />
    // do stuff<br />
    return NO;<br />
  }</code><code>}</code></p>
<p>  return YES;</p>
<p>The code above detects when the user is attempting to hit our fictitious address.  We can perform an action and then return <em>NO</em> to let the UIWebView know that it need not actually load our fictitious address.  All other attempts to load a page are met with a <em>YES </em>return.</p>
<p>You may also (and frequently will want to!) combine these two methods: use the later to know <em>when</em> to read the data, and the former to read the data.  That is, in place of <em>// do stuff </em>you can use the <em>stringByEvaluatingJavaScriptFromString:</em> function to get data out of as many form fields (including hidden form fields) as you&#8217;d like.</p>
<p>This is a four-part series on the UIWebView &#8212; please check back for more if you&#8217;re looking to go deeper.</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Jonathan Corbett</a> (President &amp; CEO, FourTen). Contact: <a href="mailto:jcorbett@fourtentech.com">jcorbett@fourtentech.com</a>.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=8&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/12/adding-web-content-to-your-app-uiwebview-part-iii-%e2%80%94-sending-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Web Content to Your App (UIWebView), Part II — Where Am I?</title>
		<link>http://learn-iphone-app-development.com/2011/01/05/adding-web-content-to-your-app-uiwebview-part-ii-%e2%80%94-where-am-i/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/05/adding-web-content-to-your-app-uiwebview-part-ii-%e2%80%94-where-am-i/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 19:10:16 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[back]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[forward]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uiwebview]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webview]]></category>

		<guid isPermaLink="false">http://learn-iphone-app-development.com/?p=6</guid>
		<description><![CDATA[This post answers the following questions: How can I build navigation (Forward, Back, etc.) for my UIWebView? How do I know what page the Web view is currently showing / user is viewing? How can I build a full &#8220;History&#8221; &#8230; <a href="http://learn-iphone-app-development.com/2011/01/05/adding-web-content-to-your-app-uiwebview-part-ii-%e2%80%94-where-am-i/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=6&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How can I build navigation (Forward, Back, etc.) for my UIWebView?</em></li>
<li><em>How do I know what page the Web view is currently showing / user is viewing?</em></li>
<li><em>How can I build a full &#8220;History&#8221; feature for a UIWebView?</em></li>
</ol>
<p>In the last post, we discussed the basics of implementing the UIWebView.  Here, we&#8217;re going to move forward to deal with navigation issues relating to the UIWebView.  When you implement a UIWebView, all that you get is a view that displays HTML content.  There are no forward or back buttons, no history, <em>etc</em>.  These all have to be implemented by you.</p>
<p>Start by dragging (or coding, if you&#8217;d prefer sans-IB) a UIWebView onto your view, but leave some room at the top for buttons.  Then, drag 2 UIButtons onto the top of your screen, double click each, and set the text to Back and Forward.  Create an outlet for each, as well as a function to receive the &#8220;press&#8221; event, Touch Up Inside.</p>
<p><code>IBOutlet UIButton *bBack, *bForward;<br />
IBOutlet UIWebView *wWw;</code><code><br />
...<br />
- (void)dontTouchMe:(id)sender;</code></p>
<p><img class="aligncenter size-full wp-image-76" style="border:1px solid black;" title="Adding a Back and Forward button" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110105-1.png?w=584&h=438" alt="" width="584" height="438" /></p>
<p>Assign the <em>dontTouchMe:</em> function to Touch Up Inside by right-dragging from the UIButtons to the View Controller (File&#8217;s Owner).   Assign the View Controller to be the delegate for the UIWebView by the same action.  Lastly, assign the outlets by the reverse drag.</p>
<p>Next, meet the <em>stringByEvaluatingJavaScriptFromString:</em> function.  This handy function lets you evaluate any JavaScript of your choosing at any time on a given UIWebView.  There also happens to be a JavaScript function to go back and to go forward.</p>
<p>Create your <em>dontTouchMe:</em> function as follows:</p>
<p><code>- (void)dontTouchMe:(id)sender {<br />
  if(sender == bBack)<br />
    [wWw stringByEvaluatingJavaScriptFromString:@"history.go(-1);"];<br />
  else if(sender == bForward)<br />
    [wWw stringByEvaluatingJavaScriptFromString:@"history.go(1);"];</code><code><br />
</code><code>}</code></p>
<p>Save and build, and your back and forward navigation are now functional!</p>
<p>If a simple back/forward aren&#8217;t enough and you&#8217;re looking to create a full browser history, you&#8217;ll need a way to figure out where the user is.  You could use the same function we used above to detect the page a user is currently viewing.  For example,</p>
<p><code>NSLog(@"%@", [wWw stringByEvaluatingJavaScriptFromString:@"document.location"]);</code></p>
<p>&#8230;will log to the console the address of the current page the user is browsing.  However, this isn&#8217;t particularly useful to us, because we need to know when the user changes pages.  We could call this function once a second and try to detect a change, but that would be a waste &#8212; there&#8217;s an easier way!</p>
<p>The UIWebView&#8217;s delegate can accept messages regarding a page change using the <em>shouldStartLoadWithRequest:</em> function.  This function allows you to detect what page the user is trying to go to before the load actually happens, and you can even refuse the page change by simply returning <em>NO</em>.</p>
<p>Declare an NSMutableArray as a member variable and let the SDK know that your View Controller conforms to the UIWebViewDelegate protocol.  In your header file:</p>
<p><code>@interface AppNameViewController : UIViewController&lt;UIWebViewDelegate&gt; {<br />
  NSMutableArray *aHistory;<br />
...</code></p>
<p>Note the protocol within brackets.</p>
<p>Allocate and initialize the array in your <em>viewDidLoad</em> function:</p>
<p><code>aHistory = [[NSMutableArray alloc] init];</code></p>
<p>&#8230;and don&#8217;t forget to release the array when your View Controller is done with it.</p>
<p>Next, we&#8217;re going to implement the function we mentioned above:</p>
<p><code>- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {<br />
  [aHistory addObject:[[NSString alloc] initWithString:[request.URL absoluteString]]];<br />
  return YES;</code><code><br />
</code><code>}</code></p>
<p>What we&#8217;ve done here is taken the URL out of the user&#8217;s request (<em>absoluteString</em> returns the full URL, including protocol and server), created a new string, and added it to our array.  After, we return <em>YES</em> to allow the UIWebView to go to the new page.  Your <em>aHistory</em> object now contains a full accounting of your browsing.</p>
<p>For a more real-world history, you&#8217;d probably also want to code such that if you push the back button, you don&#8217;t add another item to the history, but rather simply &#8220;go backwards&#8221; in the history.  To do this, simply add an <em>int </em>member variable to keep track of your position within the history array, and then before adding a new object to the array, check to see if the previous object (<em>[aHistory objectAtIndex:x-1]</em>) is equal to the new request.  If so, instead of adding the new object, simply decrement the counter.</p>
<p>This is a four-part series on the UIWebView &#8212; please check back for more if you&#8217;re looking to go deeper.</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm. For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Jonathan Corbett</a> (President &amp; CEO, FourTen). Contact: <a href="mailto:jcorbett@fourtentech.com">jcorbett@fourtentech.com</a>.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=6&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/05/adding-web-content-to-your-app-uiwebview-part-ii-%e2%80%94-where-am-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110105-1.png" medium="image">
			<media:title type="html">Adding a Back and Forward button</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Web Content to Your App (UIWebView), Part I — Loading a Page</title>
		<link>http://learn-iphone-app-development.com/2011/01/02/adding-web-content-to-your-app-uiwebview-part-i-%e2%80%94-loading-a-page/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/02/adding-web-content-to-your-app-uiwebview-part-i-%e2%80%94-loading-a-page/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 21:44:19 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[uiwebview]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webview]]></category>

		<guid isPermaLink="false">http://learniphoneappdevelopment.wordpress.com/?p=3</guid>
		<description><![CDATA[This post answers the following questions: How do I show a Web page within an app? How can I have a Web browser without launching Safari? How can I use an image file from my app bundle inside a UIWebView? &#8230; <a href="http://learn-iphone-app-development.com/2011/01/02/adding-web-content-to-your-app-uiwebview-part-i-%e2%80%94-loading-a-page/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=3&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This post answers the following questions:</em></p>
<ol>
<li><em>How do I show a Web page within an app?</em></li>
<li><em>How can I have a Web browser without launching Safari?</em></li>
<li><em>How can I use an image file from my app bundle inside a UIWebView?</em></li>
</ol>
<p>If you&#8217;re looking to show HTML content within your app, you&#8217;ll be pleased to know that Apple makes things incredibly easy in this regard.  The UIWebView object provides you with roughly the same functionality as the standard Safari browser without having to lift a finger.</p>
<p>To begin, either use Interface Builder (IB) to drag a UIWebView onto the desired view, or add it to your view in code:</p>
<p><code>UIWebView *wWw = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];<br />
[self.view addSubview:wWw];</code></p>
<p>This will add a full-screen UIWebView to the current view.  If you added your view in code, don&#8217;t forget to release the object you just allocated when you&#8217;re done!  You&#8217;ll also want to set the delegate for the UIWebView to the current view controller.  What this does is it tells the UIWebView that whenever an event happens, it&#8217;s the current view controller that gets notified (this should probably be a default, but it&#8217;s not!).  In IB, drag using the right mouse button from the UIWebView to the View Controller (File&#8217;s Owner) and select &#8220;delegate&#8221;&#8230;</p>
<p><img class="aligncenter size-full wp-image-64" title="Choosing a delegate" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-1.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>&#8230;or in code:</p>
<p><code>wWw.delegate = self;</code></p>
<p>If you&#8217;re using IB, you&#8217;ll also need to set up an outlet (a variable that corresponds to your UIWebView instance).  In the class definition, add in the following:</p>
<p><code>IBOutlet UIWebView *wWw;</code></p>
<p>&#8230;and then right drag from the View Controller to the UIWebView and select &#8220;wWw.&#8221;</p>
<p>Now that your Web view is present and all wired up, you probably want some content in it.  You can load content from a local HTML string or from the Internet, both without much difficulty.</p>
<p>To load from an HTML string, you&#8217;re going to use the loadHTMLString: method, which looks like this:</p>
<p><code>[wWw loadHTMLString:@"&lt;h1&gt;Visit &lt;a href='http://www.fourtentech.com'&gt;FourTen&lt;/a&gt; for mobile application development!&lt;/h1&gt;" baseURL:nil];</code></p>
<p>If you&#8217;re simply trying to display HTML formatted content, you&#8217;re actually done!  You can simply edit the HTML string as desired, and your markup will be displayed as it would in Safari.</p>
<p><img class="aligncenter size-full wp-image-65" title="Loading a simple HTML string into a UIWebView" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-2.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>If you want to embed images that you&#8217;ve put in your app bundle within your HTML, you&#8217;ll also need to set the baseURL.  Normally when you go to a Web page, you type in an address, or click on a link that contains an address, and your browser &#8220;knows&#8221; where you are.  If you were to type:</p>
<p><code>&lt;img src='410logo.png' /&gt;</code></p>
<p>&#8230;in your HTML, your browser would know that you really want to show <a href="http://[server]/[current_dir]/410logo.png">http://[server]/[current_dir]/410logo.png</a>.  When you&#8217;re loading an HTML string into a UIWebView, there&#8217;s no way for the UIWebView to know where it is unless you tell it, and if you want local images to show, you simply pass it the path of the local app bundle:</p>
<p><code>[wWw loadHTMLString:@"&lt;center&gt;&lt;img src='410logo.png' style='margin-top:150px;' /&gt;&lt;/center&gt;" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];</code></p>
<p>We&#8217;re all about succinct code here at FourTen, so we actually did several things in that one line above.  We got the application bundle path using [[NSBundle mainBundle] bundlePath], and then we used that to create an NSURL object.  That NSURL object becomes our new baseURL, and now, local images will show.  The code above will get you:</p>
<p><img class="aligncenter size-full wp-image-63" title="UIWebView with local image" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-3.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>To show a remote Web page, it&#8217;s just as easy, if not easier.  You&#8217;ll need the following:</p>
<p><code>[wWw loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.fourtentech.com/"]]];</code></p>
<p> We&#8217;ve also done several things in this line: we created a NSURL from a string, used that to create an NSURLRequest, and fed that to loadRequest.  As long as your device or simulator has Internet access, you&#8217;ll end up here:</p>
<p><img class="aligncenter size-full wp-image-66" title="FourTen home page in a UIWebView" src="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-4.png?w=584" alt=""   style="border:1px solid black;" /></p>
<p>This is a four-part series on the UIWebView &#8212; please check back for more if you&#8217;re looking to go deeper.</p>
<p><em>FourTen Technologies, Inc., is a leading US <a href="http://www.fourtentech.com/services/iphone/">iPhone app development</a> firm.  For information on having FourTen build a custom mobile application for your company, visit www.<a href="http://www.fourtentech.com/">fourtentech</a>.com. Article written by <a href="http://www.fourtentech.com/about/whoswho/">Jonathan Corbett</a> (President &amp; CEO, FourTen).  Contact: <a href="mailto:jcorbett@fourtentech.com">jcorbett@fourtentech.com</a>.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=3&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/02/adding-web-content-to-your-app-uiwebview-part-i-%e2%80%94-loading-a-page/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-1.png" medium="image">
			<media:title type="html">Choosing a delegate</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-2.png" medium="image">
			<media:title type="html">Loading a simple HTML string into a UIWebView</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-3.png" medium="image">
			<media:title type="html">UIWebView with local image</media:title>
		</media:content>

		<media:content url="http://learniphoneappdevelopment.files.wordpress.com/2011/01/20110102-4.png" medium="image">
			<media:title type="html">FourTen home page in a UIWebView</media:title>
		</media:content>
	</item>
		<item>
		<title>Welcome to Learn iPhone App Development with FourTen Technologies!</title>
		<link>http://learn-iphone-app-development.com/2011/01/01/welcome-to-learn-iphone-app-development-with-fourten-technologies/</link>
		<comments>http://learn-iphone-app-development.com/2011/01/01/welcome-to-learn-iphone-app-development-with-fourten-technologies/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 15:14:44 +0000</pubDate>
		<dc:creator>410technologies</dc:creator>
				<category><![CDATA[Site Info]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[fourten]]></category>
		<category><![CDATA[fourtentech]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[technologies]]></category>
		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://learniphoneappdevelopment.wordpress.com/?p=1</guid>
		<description><![CDATA[Welcome!  We&#8217;re kicking off the new year by giving back to the development community.  iPhone development, as far as we&#8217;re concerned, is still a brand new field, and even the most experienced iPhone developers out there have been at it &#8230; <a href="http://learn-iphone-app-development.com/2011/01/01/welcome-to-learn-iphone-app-development-with-fourten-technologies/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=1&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome!  We&#8217;re kicking off the new year by giving back to the development community.  iPhone development, as far as we&#8217;re concerned, is still a brand new field, and even the most experienced iPhone developers out there have been at it for only 3+ years.  So, we&#8217;re all still learning, and FourTen extends its 10+ years of Web and software development and 3 years of iPhone development experience to you &#8212; free.</p>
<p>If you&#8217;ve not yet heard of FourTen, we are a leading US software development firm in the field of mobile applications.  When mobile platforms became powerful in 2007, our customers started asking us if we could put our development experience towards the new market.  Today, not even 4 years later, 80% of our revenue is mobile.  And we love it.</p>
<p>We&#8217;re a 100% US company, we don&#8217;t outsource, and our staff in New York and Miami have learned a lot over the last few years.   We hope it helps!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learniphoneappdevelopment.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learniphoneappdevelopment.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learniphoneappdevelopment.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learniphoneappdevelopment.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learniphoneappdevelopment.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learniphoneappdevelopment.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learniphoneappdevelopment.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learniphoneappdevelopment.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learn-iphone-app-development.com&#038;blog=20582334&#038;post=1&#038;subd=learniphoneappdevelopment&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learn-iphone-app-development.com/2011/01/01/welcome-to-learn-iphone-app-development-with-fourten-technologies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce6145dd6ce288f54a3d10208f2b314c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">410technologies</media:title>
		</media:content>
	</item>
	</channel>
</rss>
