<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iphone and gis development notes &#187; iphone</title>
	<atom:link href="http:///wordpress/tag/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>By Rupert</description>
	<lastBuildDate>Mon, 26 Jul 2010 05:06:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iPhone Cross Application Launch/Marketing Strategy</title>
		<link>/wordpress/2010/07/iphone-cross-application-launchmarketing-strategy/</link>
		<comments>/wordpress/2010/07/iphone-cross-application-launchmarketing-strategy/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 23:42:02 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=714</guid>
		<description><![CDATA[As many developers keep on asking me how I reached the rankings I have now for MyTravelPhilippines, I would like to share the marketing/launch strategy that we did. The strategy is not new. I&#8217;ve read from numerous iphone developer blogs who have a few apps in the store about cross app promotion. But how do]]></description>
			<content:encoded><![CDATA[<p>As many developers keep on asking me how I reached the rankings I have now for <a href="http://www.mytravelphilippines.com/">MyTravelPhilippines</a>, I would like to share the marketing/launch strategy that we did. The strategy is not new. I&#8217;ve read from numerous iphone developer blogs who have a few apps in the store about cross app promotion. But how do you really do it?</p>
<p>On Dec 2009, I have released the &#8220;Philippines 2010 Election Survey&#8221;.  The red dot is on May 11 which is the actual elections for the Philippines. However after this event, you can see the downloads went down.. well because the elections are over&#8230;<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo1.jpg" alt="photo1.jpg" border="0" width="480" height="320" /></p>
<p>When the election results came out from the government, I immediately made the app, &#8220;Philippines 2010 Election Results&#8221;. I have launched this on June 26. I was hoping that most users would be eager to see the results and most did update to the new app. Within the updated app, I made a link to download &#8220;MyTravelPhilippines&#8221; in the appstore.<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo3.png" alt="photo3.png" border="0" width="320" height="480" /></p>
<p>The election app has a total of 4k users where 25% updated. Consequently, the &#8220;MyTravelPhilippines&#8221; eyeball did do the trick and on June 26 we had 849 downloads.<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo2.jpg" alt="photo2.jpg" border="0" width="480" height="320" /></p>
<p>The 849 downloads on June 26 was significant as it was able to push &#8220;MyTravelPhilippines&#8221; to rank #1(Free Philippines Travel Category) and rank #9 (Free Philippines Overall).<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo4.jpg" alt="photo4.jpg" border="0" width="320" height="480" /></p>
<p>In just two weeks, I was able to hit 5k mark for MyTravelPhilippines which took me 6 months to do in the Philippines Elections app.</p>
<p>What I&#8217;ve learned?<br />
- Use an <strong>event</strong>, in this case the <em>election results</em>, to get most out of the updates.<br />
- Cross app promotion works. It&#8217;s like migrating your users from one app to another.<br />
- Application Visibility is very important. Try hard to make it to the Top 10 in that category. (Yes, I know its easier said that done.. but really aim for this..)</p>
<p>What I&#8217;ve missed?<br />
<strong>Application updates to keep the app alive.</strong> This would help in <em>&#8220;the download and never open again or open occasionally syndrome&#8221;</em>. At the time of this writing, I am currently trying to do this as I could see the graph is slowly trending down. What I should have anticipated is to keep at least one version higher (1.1) and uploading the older version(1.0) on the store. The timing of this updates could be periodical&#8211;after 3 weeks, a month or an event. But with the limited resources that we had, only a two man team, and no marketing $$$ expense at all in ads, it was a great experience.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/07/iphone-cross-application-launchmarketing-strategy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging, MyTravelPhilippines, Navteq</title>
		<link>/wordpress/2010/07/blogging-mytravelphilippines-navteq/</link>
		<comments>/wordpress/2010/07/blogging-mytravelphilippines-navteq/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 00:24:09 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">/wordpress/?p=710</guid>
		<description><![CDATA[I have neglected this blog for the past few months because of the past activities I was involved in. It was a fruitful year for the iPhone as I have launched two successful and rewarding projects. 1. The iphone app for a client in the beforeYouDig industry has extremely improved over the past 6 months.]]></description>
			<content:encoded><![CDATA[<p>I have neglected this blog for the past few months because of the past activities I was involved in. It was a fruitful year for the iPhone as I have launched two successful and rewarding projects. </p>
<p>1. The iphone app for a client in the beforeYouDig industry has extremely improved over the past 6 months. It has won <a href="http://corporate.navteq.com/webapps/NewsUserServlet?action=NewsDetail&#038;newsId=897&#038;lang=en&#038;englishonly=false">second place in the Navteq LBS Challenge for APAC.</a> If you have been following my posts, this was related to route-me. Hopefully, we should launch this in the AppStore soon. Stay tuned&#8230;</p>
<p>2. <a href="http://www.mytravelphilippines.com">MyTravelPhilippines</a> was launched last April on the web. After that, I started working on the mobile version on the iPhone. I pushed it in the store on June 15 and became Top 10 Free after a week in the PH store, and Top 1 in Travel Free category for the PH store. This was really great as we haven&#8217;t spent any $$$ on the marketing and relied on friends, facebook, etc for viral marketing. I am pushing again for another release before this month ends. Again, stay tuned.</p>
<p>So to break the ice.. I will be blogging again&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/07/blogging-mytravelphilippines-navteq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #20:Integrating Mapserver/TileCache to RouteMe</title>
		<link>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/</link>
		<comments>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 01:37:57 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">/wordpress/?p=700</guid>
		<description><![CDATA[Below is a summary of how I was able to implement Mapserver, TileCache and Route-Me iPhone Mapping Framework. 1. Assuming you have a working Mapserver/TileCache setup. Take note of the ff parameters: resolution and bbox. Below is my tilecache.cfg: 61 [mapserver_australia_3857] 62 type=MapServerLayer 63 mapfile=/Users/rupert/projects/pelicancorp/DMOB/trunk/map/australia_3857.map 64 layers=all 65 extension=jpg 66 bbox=-20037508.34, -20037508.34, 20037508.34, 20037508.34 68]]></description>
			<content:encoded><![CDATA[<p>Below is a summary of how I was able to implement Mapserver, TileCache and Route-Me iPhone Mapping Framework. </p>
<p>1.  Assuming you have a <strong>working</strong> Mapserver/TileCache setup. Take note of the ff parameters: resolution and bbox. Below is my tilecache.cfg:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;"> 61 [mapserver_australia_3857]
 62 type=MapServerLayer
 63 mapfile=/Users/rupert/projects/pelicancorp/DMOB/trunk/map/australia_3857.map
 64 layers=all
 65 extension=jpg
 66 bbox=-20037508.34, -20037508.34, 20037508.34, 20037508.34
 68 maxResolution=156543.033928041
 70 levels=20
 71 srs=EPSG:3857
 72 tms_type=google
 73 extent_type=loose
 74 spherical_mercator=true</pre></div></div>

<p>2. Grab the RMGenericMercatorWMSSource from <a href="http://groups.google.com/group/route-me-map/browse_thread/thread/b58fa1d20cf15823/e30c42d9c90a8170?lnk=gst&#038;q=Generic#e30c42d9c90a8170">http://groups.google.com/group/route-me-map/browse_thread/thread/b58fa1d20cf15823/e30c42d9c90a8170?lnk=gst&#038;q=Generic#e30c42d9c90a8170</a></p>
<p>3. By default without any changes, the RMGenericMercatorWMSSource could display Mapserver WMS Tiles. This is possible by passing an NSDictionary *parameters, which contains arrayValues and arrayKeys for creating an http 256&#215;256 image request to the http://127.0.0.1/cgi-bin/mapserv binary.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//This would request to http://127.0.0.1/cgi-bin/mapserv</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayValues <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/path-to/australia_3857.map&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;all&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;png&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayKeys <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAP&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LAYERS&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>wmsParameters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span> arrayValues forKeys<span style="color: #002200;">:</span>arrayKeys <span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Resulting http requests to the mapserv binary:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://192.168.1.193:81/tilecache/tilecache.py?LAYERS=australia_3857&amp;SRS=EPSG:3857&amp;REQUEST=GetMap&amp;SERVICE=WMS&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;FORMAT=png&amp;VERSION=1.1.1&amp;WIDTH=256&amp;HEIGHT=256&amp;BBOX=16828376.000000,-4006523.000000,16833268.000000,-4001631.000000</pre></div></div>

<p>Note that the bbox values does not contain decimal places. Nevertheless, it still works on Mapserver.</p>
<p>4. Now, assuming we have a valid tilecache running. And it is tested from browser, i.e http://127.0.0.1/map/tilecache_3857.html, open up firebug to see the requests. Below is a sample&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://192.168.1.193:81/tilecache/tilecache.py?LAYERS=australia_3857&amp;FORMAT=jpg&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetMap&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;SRS=EPSG%3A3857&amp;BBOX=16123932.497377,-4539747.9811239,16143500.376618,-4520180.1018829&amp;WIDTH=256&amp;HEIGHT=256</pre></div></div>

<p>But it seems, route-me is not supplying the bbox values accurately, as the decimal values is truncated (BBOX=16828376.000000,-4006523.000000,16833268.000000,-4001631.000000) from our previous request(3). </p>
<p>After changing the wmsParameter values to create a tilecache request, I noticed that route-me is not displaying the tiles correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Testing for Windows:TileCache - ?</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayValues <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;australia_3857&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;png&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//for WIndows</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//TileCache URL Parameters:</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayKeys <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LAYERS&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>5. The workaround is to use &#8220;double&#8221; instead of &#8220;floats&#8221; in the RMGenericMercatorWMSSource. You can download the zip from <a href="/wordpress/wp-content/uploads/2010/01/RMGenericMercatorWMSSource.zip" title="RMGenericMercatorWMSSource.zip">RMGenericMercatorWMSSource.zip</a>. I have modified &#8220;initialResolution&#8221; and &#8220;originShift&#8221; to both use <em>&#8220;double&#8221;</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">double</span> x;
	<span style="color: #a61390;">double</span> y;
<span style="color: #002200;">&#125;</span> CGDoublePoint;
&nbsp;
<span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span> 
	CGDoublePoint ul; 
	CGDoublePoint lr; 
<span style="color: #002200;">&#125;</span> CGXYRect;</pre></div></div>

<p>Afterwards, I copied the maxResolution and bbox (tilecache) and specified it for the initialResoultion and originShift respectively.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;RMGenericMercatorWMSSource.h&quot;</span>
&nbsp;
CGFloat DegreesToRadians<span style="color: #002200;">&#40;</span>CGFloat degrees<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><span style="color: #a61390;">return</span> degrees <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>;<span style="color: #002200;">&#125;</span>; 
CGFloat RadiansToDegrees<span style="color: #002200;">&#40;</span>CGFloat radians<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><span style="color: #a61390;">return</span> radians <span style="color: #002200;">*</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">/</span> M_PI;<span style="color: #002200;">&#125;</span>; 
&nbsp;
<span style="color: #a61390;">@implementation</span> RMGenericMercatorWMSSource
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithBaseUrl<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>baseUrl parameters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>params
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>; 
&nbsp;
	<span style="color: #11740a; font-style: italic;">// 156543.03392804062 for sideLength 256 pixels </span>
	<span style="color: #11740a; font-style: italic;">// initialResolution = 2 * M_PI * 6378137 / [self tileSideLength];</span>
	<span style="color: #11740a; font-style: italic;">// specify here whatever the resolution is from tilecache.</span>
	initialResolution <span style="color: #002200;">=</span> <span style="color: #2400d9;">156543.033928041</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// 20037508.342789244 </span>
	<span style="color: #11740a; font-style: italic;">//originShift = 2 * M_PI * 6378137 / 2;</span>
	<span style="color: #11740a; font-style: italic;">//originShift = 20037508.342789244f;</span>
	<span style="color: #11740a; font-style: italic;">// specify here whatever the bbox is from tilecache.</span>
	originShift <span style="color: #002200;">=</span> <span style="color: #2400d9;">20037508.32</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test initialResolution:%f originShift:%f&quot;</span>, initialResolution, originShift<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// setup default parameters</span>
	<span style="color: #11740a; font-style: italic;">// use official EPSG:3857 by default, user can override to 900913 if needed.</span>
	wmsParameters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;image/png&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;GetMap&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;1.1.1&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;WMS&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span> 
											  forKeys<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;REQUEST&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;VERSION&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SERVICE&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>wmsParameters addEntriesFromDictionary<span style="color: #002200;">:</span>params<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// build WMS request URL template</span>
	urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithString<span style="color: #002200;">:</span>baseUrl<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSEnumerator</span> <span style="color: #002200;">*</span>e <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>wmsParameters keyEnumerator<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>key;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>delimiter <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;
	<span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span>key <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>e nextObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@%@=%@&quot;</span>,
					   delimiter,
					   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>key uppercaseString<span style="color: #002200;">&#93;</span> stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSASCIIStringEncoding<span style="color: #002200;">&#93;</span>, 
					   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>wmsParameters objectForKey<span style="color: #002200;">:</span>key<span style="color: #002200;">&#93;</span> stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSASCIIStringEncoding<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
		delimiter <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;&quot;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">int</span> sideLength <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span>self tileSideLength<span style="color: #002200;">&#93;</span>;
	urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;WIDTH=%d&amp;HEIGHT=%d&quot;</span>,sideLength,sideLength<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// implement in subclass?</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> uniqueTilecacheKey
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AbstractMercatorWMSSource&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>shortName
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>longDescription
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>shortAttribution
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>longAttribution
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> minZoom
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> 1.0f;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> maxZoom
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> 19.0f;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857 </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span> LatLonToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CLLocationCoordinate2D<span style="color: #002200;">&#41;</span> latlon 
<span style="color: #002200;">&#123;</span> 
	CGPoint meters; 
	meters.x <span style="color: #002200;">=</span> latlon.longitude <span style="color: #002200;">*</span> originShift <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>; 
	meters.y <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">log</span><span style="color: #002200;">&#40;</span> <span style="color: #a61390;">tan</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">90.0</span> <span style="color: #002200;">+</span> latlon.latitude<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">360.0</span> <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">/</span> <span style="color: #002200;">&#40;</span>M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> originShift <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>; 
	<span style="color: #a61390;">return</span> meters; 
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Converts XY point from Spherical Mercator EPSG:3857 to lat/lon in WGS84 Datum </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CLLocationCoordinate2D<span style="color: #002200;">&#41;</span> MetersToLatLon<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span> meters 
<span style="color: #002200;">&#123;</span> 
	CLLocationCoordinate2D latlon; 
	latlon.longitude <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>meters.x <span style="color: #002200;">/</span> originShift<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">180.0</span>; 
	latlon.latitude <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>meters.y <span style="color: #002200;">/</span> originShift<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">180.0</span>; 
	<span style="color: #11740a; font-style: italic;">//latlon.latitude = - 180 / M_PI * (2 * atan( exp( latlon.latitude * M_PI / 180.0)) - M_PI / 2.0); </span>
	latlon.latitude <span style="color: #002200;">=</span> <span style="color: #2400d9;">180</span> <span style="color: #002200;">/</span> M_PI <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span> <span style="color: #002200;">*</span> <span style="color: #a61390;">atan</span><span style="color: #002200;">&#40;</span> <span style="color: #a61390;">exp</span><span style="color: #002200;">&#40;</span> latlon.latitude <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>; 
	<span style="color: #a61390;">return</span> latlon; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #11740a; font-style: italic;">// Converts pixel coordinates in given zoom level of pyramid to EPSG:3857 </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGDoublePoint<span style="color: #002200;">&#41;</span> PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> px PixelY<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>py atZoom<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>zoom 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">double</span> resolution <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self ResolutionAtZoom<span style="color: #002200;">:</span> zoom<span style="color: #002200;">&#93;</span>; 
	CGDoublePoint meters; 
	<span style="color: #a61390;">double</span> x <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>px <span style="color: #002200;">*</span> resolution <span style="color: #002200;">-</span> originShift<span style="color: #002200;">&#41;</span>; 
	<span style="color: #a61390;">double</span> y <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>py <span style="color: #002200;">*</span> resolution <span style="color: #002200;">-</span> originShift<span style="color: #002200;">&#41;</span>; 
&nbsp;
	meters.x <span style="color: #002200;">=</span> x;
	meters.y <span style="color: #002200;">=</span> y;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;px: %d py: %d resolution: %f originShift: %f x: %f y: %f&quot;</span>, px, py, resolution, originShift, x, y<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> meters; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> tileURL<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>RMTile<span style="color: #002200;">&#41;</span> tile 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #11740a; font-style: italic;">//RMLatLongBounds tileBounds = [self TileLatLonBounds:tile];</span>
	<span style="color: #11740a; font-style: italic;">// Get BBOX coordinates in meters</span>
	CGXYRect tileBounds <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self TileBounds<span style="color: #002200;">:</span>tile<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;BBOX=%f,%f,%f,%f&quot;</span>,
					 tileBounds.ul.x,
					 tileBounds.lr.y,
					 tileBounds.lr.x,
					 tileBounds.ul.y<span style="color: #002200;">&#93;</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Tile %d,%d,%d yields %@&quot;</span>,tile.zoom, tile.x, tile.y, url<span style="color: #002200;">&#41;</span>; 
&nbsp;
	<span style="color: #a61390;">return</span> url; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Returns bounds of the given tile in EPSG:3857 coordinates </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGXYRect<span style="color: #002200;">&#41;</span>  TileBounds<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>RMTile<span style="color: #002200;">&#41;</span> tile 
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> sideLength <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span>self tileSideLength<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">int</span> zoom <span style="color: #002200;">=</span> tile.zoom;
	<span style="color: #a61390;">long</span> twoToZoom <span style="color: #002200;">=</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>,zoom<span style="color: #002200;">&#41;</span>;
	CGXYRect tileBounds; 
	tileBounds.ul <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>tile.x <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  PixelY<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>twoToZoom<span style="color: #002200;">-</span>tile.y<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  atZoom<span style="color: #002200;">:</span> zoom <span style="color: #002200;">&#93;</span>; 
	tileBounds.lr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>tile.x<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  PixelY<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>twoToZoom<span style="color: #002200;">-</span>tile.y<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  atZoom<span style="color: #002200;">:</span> zoom<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> tileBounds; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #11740a; font-style: italic;">//Resolution (meters/pixel) for given zoom level (measured at Equator) </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> ResolutionAtZoom <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> zoom 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">return</span> initialResolution <span style="color: #002200;">/</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>,zoom<span style="color: #002200;">&#41;</span>; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>6. Download <a href="/wordpress/wp-content/uploads/2010/01/TileCache_RouteMe.zip" title="TileCache_RouteMe.zip">TileCache_RouteMe.zip</a> Note: You need a valid mapserver and tilecache running.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #19: Route-Me: Opensource mapping for the iphone</title>
		<link>/wordpress/2009/12/iphone-dev-note-19-route-me-opensource-mapping-for-the-iphone/</link>
		<comments>/wordpress/2009/12/iphone-dev-note-19-route-me-opensource-mapping-for-the-iphone/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 05:34:51 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=671</guid>
		<description><![CDATA[Route-Me is an opensource mapping api similar to the MapKit.framework. The main project resides in googlecode (http://code.google.com/p/route-me/). Part 1: Making the Sample Apps work. 1. Download the code from svn. svn co http://route-me.googlecode.com/svn/trunk/ route-me 2. In the route-me directory, you would have 3 directories: - MapView &#8211; this contains the mapping framework - Proj4 &#8211;]]></description>
			<content:encoded><![CDATA[<p>Route-Me is an opensource mapping api similar to the MapKit.framework. The main project resides in googlecode (<a href="http://code.google.com/p/route-me/">http://code.google.com/p/route-me/</a>).</p>
<h3>Part 1: Making the Sample Apps work.</h3>
<p>1. Download the code from svn.<br />
svn co http://route-me.googlecode.com/svn/trunk/ route-me</p>
<p>2. In the route-me directory, you would have 3 directories:<br />
- MapView &#8211; this contains the mapping framework<br />
- Proj4   &#8211; projection library.<br />
- samples</p>
<p>3. Build MapView. I encountered some problems here, particularly this specific <a href="http://code.google.com/p/route-me/issues/detail?id=114">issue: Cannot build on 3.1 using iphone simulator</a>. </p>
<p><strong>How to make the build?</strong> Now, at the time of this writing, I have XCode3.1.4 and iPhone 3.0, 3.1, 3.1.2. Edit the project settings so that the &#8220;build&#8221; and &#8220;release&#8221; will point to use 3.0.  If you encounter a problem, it is best to &#8220;Clean All&#8221;, remove the build directory, then &#8220;Build&#8221; again. To verfiy if you have a successful build, notice that libMapView.a was created.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-libMapView.png" alt="routeme-libMapView.png" border="0" width="274" height="218" /></p>
<p>Note: Notice here that I have <strong>libMapView.a</strong> both in <em>Debug-iphoneos/</em> and <em>Debug-iphonesimulator/</em></p>
<p>No need to build Proj4 as long as it is sitting on the same directory where MapView is. </p>
<p>4. To test route-me, we can study from the samples directory. Let&#8217;s build samples/SampleMap. Notice that SampleMap has a reference to MapView.xcodeproj. </p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-samplemap.png" alt="routeme-samplemap.png" border="0" width="179" height="102" /></p>
<p>Similarly, we can build this using 3.0 both in the simulator and device.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-samplemap-ok.jpg" alt="routeme-samplemap-ok.jpg" border="0" width="161" height="243" /></p>
<h3>Part 2: Integrating with your own project.</h3>
<p>Reference: <a href="http://code.google.com/p/route-me/wiki/EmbeddingGuide">http://code.google.com/p/route-me/wiki/EmbeddingGuide</a></p>
<p>1. Create a view-based project: MyRMSampleMap. </p>
<p>2. Project -> &#8220;Add To Project&#8221;. Make the reference type as &#8220;Relative to Project&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-referencing-mapview.jpg" alt="routeme-referencing-mapview.jpg" border="0" width="250" height="233" /></p>
<p>3. Configure your project to have a direct dependency with MapView.xcodeproj. Follow the instructions exactly as stated from the EmbeddingGuide.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-ref-dd.jpg" alt="routeme-ref-dd.jpg" border="0" width="275" height="417" /></p>
<blockquote><p>Click on the &#8220;Build&#8221; tab in your target&#8217;s info window.</p>
<p>Change the Configuration popup to read &#8220;All Configurations&#8221;, so that your changes can be made just once.</p>
<p>Find &#8220;Header Search Paths&#8221; under &#8220;Search Paths&#8221; (shortcut: type &#8220;header&#8221; in the search box at upper right of the target info window). Double-click on the &#8216;Header Search Paths&#8217; text and add the path to the MapView directory contained in the route-me project located on your file system. (Note that if there are any spaces in the path, enclose the entire entry with &#8220;&#8221;. If the MapView project folder is placed next to your project&#8217;s project folder on the file system, you would have the following in the path: &#8220;../MapView&#8221;.</p>
<p>Check the &#8216;Recursive&#8217; box and click Ok. </p></blockquote>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-searchpaths.jpg" alt="routeme-searchpaths.jpg" border="0" width="400" height="205" /></p>
<p>4. Make a test &#8220;Build&#8221;.</p>
<p>5. Add a reference to:<br />
- QuartzCore.framework<br />
- libsqlite3.dylib</p>
<p>6. Let&#8217;s add our mapview in the interface: MyRMSampleMapViewController.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;RMMapView.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MyRMSampleMapViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	RMMapView <span style="color: #002200;">*</span>mapview;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> RMMapView <span style="color: #002200;">*</span>mapview;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>7. In the implementation, add this snippet.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> mapview;
...
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewWillAppear<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated<span style="color: #002200;">&#123;</span>
	mapview <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>RMMapView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 320.0f, 460.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>mapview setBackgroundColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>mapview<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Download: <a href="/wordpress/wp-content/uploads/2009/12/MyRMSampleMap.zip" title="MyRMSampleMap.zip">MyRMSampleMap.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/12/iphone-dev-note-19-route-me-opensource-mapping-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #18: Integrating Ads (AdMob) on your iPhone App</title>
		<link>/wordpress/2009/12/iphone-dev-note-18-integrating-ads-admob-on-your-iphone-app/</link>
		<comments>/wordpress/2009/12/iphone-dev-note-18-integrating-ads-admob-on-your-iphone-app/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 00:46:39 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=657</guid>
		<description><![CDATA[Basic Info What is common with these ad platforms? Each application is offered a unique id which needs to be specified during development. What is publishing? Publishing allows the developer to display (publish) ads on the native application. What is CPM? Impressions per thousand. Normally ad networks pays $1 for every 1000 CPM. So you]]></description>
			<content:encoded><![CDATA[<h2>Basic Info</h2>
<p><strong>What is common with these ad platforms?</strong><br />
Each application is offered a unique id which needs to be specified during development.</p>
<p><strong>What is publishing?</strong><br />
Publishing allows the developer to display (<em>publish</em>) ads on the native application.</p>
<p><strong>What is CPM?</strong><br />
Impressions per thousand. Normally ad networks pays $1 for every 1000 CPM. So you need 1000 page views (not clicks) to earn a buck.</p>
<p><strong>What is the fillrate?</strong><br />
The percentage of impressions served based on total requests for ads. This is number to look for when you get blank ads. How many of my clients gets an ad impression? I had 60%</p>
<p><strong>What is the Click Through Rate (CTR)?</strong><br />
Out of 60% of my clients who had ad impressions, 6.18% of them clicked the ad. The more they get clicked, the higher your revenue.</p>
<h2><a href="http://www.admob.com">Admob</a></h2>
<p>Offers both publishing and analytics. Currently offers both iPhone and Android. Able to publish ads for native app and mobile websites. This is my preferred ad network of choice as it is easier to setup than the others. And just recently, it was swallowed by Google, whether that is good or bad for us, we have yet to know.</p>
<p><a href="http://developer.admob.com/wiki/IPhone#SDK_Integration_instructions">AdMob Iphone SDK Integration</a></p>
<p>1. After signing up/registering to Admob you need to add your application in &#8220;Sites &#038; Apps&#8221; tab (2nd tab from the left).</p>
<p>2. Click on &#8220;Add Site/App&#8221; and you would be presented with what kind of site or app type (Mobile Web, Iphone App, Iphone Web and Android App). Select &#8220;Iphone App&#8221; and fill out the details..</p>
<p>3. If you go to &#8220;Sites &#038; Apps&#8221;, there&#8217;s a link &#8220;Setup&#8221; just under the Quick Links. You could download a sample AdMob application there wherein your publisherId is already built-in. Here&#8217;s a sample (<a href="/wordpress/wp-content/uploads/2009/12/admob_iphone_sdk_20091119.tar.gz" title="admob_iphone_sdk_20091119.tar.gz">admob_iphone_sdk_20091119.tar.gz</a>). Note that AdMob upgrade their code, notice the dates (20091119)? So it&#8217;s good practice to read the CHANGELOG.</p>
<p>4. Note your publisherId.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark Admob delegate methods</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>publisherId <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;a14ac98028663b0&quot;</span>; <span style="color: #11740a; font-style: italic;">// bayanihan</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>5. Make the sample application from AdMob run first before integrating your app.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// To receive test ads rather than real ads...</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>useTestAd <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>; <span style="color: #11740a; font-style: italic;">//change this to NO later..</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>6. Normally, the problems/quirks I experience when integrating a 3rd Party Project are framework references. So, here&#8217;s mine:</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/admob_frameworks.png" alt="admob_frameworks.png" border="0" width="221" height="172" /></p>
<p>Note: As of ver 20091119, I added <em>MessageUI.framework, AudioToolbox.framework, MediaPlayer.framework</em>. Prior to that build (200906xx), I don&#8217;t have those.  If you are compiling against iPhoneOS version 3, then you would need to reference <em>libAdMObDevice3_0.a</em> and <em>libAdMobSimulator3_0.a</em> (to run it in the simulator&#8211;but you would take this reference off when making an actual build)</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/admob-iphoneos3.png" alt="admob-iphoneos3.png" border="0" width="204" height="85" /></p>
<p>7. Now, that both the testAd (YES) is working, it might take you a few hours before the real ad comes in. Be patient. :)</p>
<p>8. Integrate to your project. AdMob provided detailed examples on how to integrate depending on your needs&#8211;Interface Builder (IB), Programmatically or TableView.  Personally, I have used both IB and TableView and it works flawlessly.</p>
<p>9. I dont get an ad? I get an Ad? Which one? Check out the AdMobDelegate Methods.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>didReceiveAd<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>AdMobView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>adView <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AdMob: Did receive ad&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>didFailToReceiveAd<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>AdMobView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>adView <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AdMob: Did fail to receive ad&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//[self createMobclix];</span>
	<span style="color: #11740a; font-style: italic;">//[bannerCell setNeedsLayout];</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>10. Now once you have AdMob going, you want to be more efficient and get higher fill rates. You can checkout other Ad Platforms (<a href="https://developer.mobclix.com/">Mobclix</a>, <a href="www.adwhirl.com">Adwhirl</a>). Notice on step 9 above, that if I don&#8217;t get an ad from AdMob, I fire up an add from MobClix.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/12/iphone-dev-note-18-integrating-ads-admob-on-your-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #17: Displaying a custom view controller from a UITextField</title>
		<link>/wordpress/2009/11/iphone-note-17-displaying-a-custom-view-controller-from-a-uitextfield/</link>
		<comments>/wordpress/2009/11/iphone-note-17-displaying-a-custom-view-controller-from-a-uitextfield/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 00:49:56 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=636</guid>
		<description><![CDATA[Problem: I want my textFieldSearchAddress to display a seperate viewcontroller. Short Answer: Hide the keyboard by using [textField resignFirstResponder] then show the view controller. 1. Implement a UITextFieldDelegate. - &#40;BOOL&#41;textFieldShouldBeginEditing:&#40;UITextField *&#41;textField&#123; &#91;textField resignFirstResponder&#93;; &#91;self show&#93;; return NO; &#125; Be careful with the BOOL return of textFieldShouldBeginEditing. From the docs: &#8220;YES if an editing session should]]></description>
			<content:encoded><![CDATA[<p>Problem: I want my textFieldSearchAddress to display a seperate viewcontroller.</p>
<p><img src="/wordpress/wp-content/uploads/2009/11/textfield.png" alt="textfield.png" border="0" width="400" height="279" /></p>
<p>Short Answer: Hide the keyboard by using
<pre>[textField resignFirstResponder]</pre>
<p> then show the view controller.</p>
<p>1. Implement a UITextFieldDelegate.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>textFieldShouldBeginEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITextField <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>textField<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>textField resignFirstResponder<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self show<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Be careful with the BOOL return of textFieldShouldBeginEditing. From the docs: <em>&#8220;YES if an editing session should be initiated; otherwise, NO to disallow editing.&#8221;</em> </p>
<p>2. Show the view controller.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>show<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;show&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	AddressViewController <span style="color: #002200;">*</span>addressViewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>AddressViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AddressViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	UINavigationController <span style="color: #002200;">*</span>nav <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationController alloc<span style="color: #002200;">&#93;</span> initWithRootViewController<span style="color: #002200;">:</span>addressViewController<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>nav animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>addressViewController release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>nav release<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Download <a href="/wordpress/wp-content/uploads/2009/11/SimpleIB-textfield_custom_view_controller.zip" title="SimpleIB-textfield_custom_view_controller.zip">SimpleIB-textfield_custom_view_controller.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/11/iphone-note-17-displaying-a-custom-view-controller-from-a-uitextfield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #16: Creating a MKMapView using IB</title>
		<link>/wordpress/2009/10/iphone-dev-16-creating-a-mkmapview-using-ib/</link>
		<comments>/wordpress/2009/10/iphone-dev-16-creating-a-mkmapview-using-ib/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 06:25:59 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=590</guid>
		<description><![CDATA[In this tutorial we will be addking MKMapView using IB to a ViewController. 1. XCode -> File -> New Project -> View-based Application. Name the project &#8220;SimpleMapIB&#8221; 2. Make sure everything works out accordingly before doing anything. Let&#8217;s test from the iPhone Simulator. Click on &#8220;Build and Go&#8221;. You should see the iPhone Simulator running]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we will be addking MKMapView using IB to a ViewController.</p>
<p>1. XCode -> File -> New Project -> View-based Application.</p>
<p>Name the project &#8220;SimpleMapIB&#8221;</p>
<p>2. Make sure everything works out accordingly before doing anything. Let&#8217;s test from the iPhone Simulator. Click on <b>&#8220;Build and Go&#8221;</b>. You should see the iPhone Simulator running with a gray background. Bring up the Debugger Console (XCode -> Run -> Console) as well and it should be free from errors.</p>
<p>3. Now double-click on &#8220;SimpleMapIBViewController.xib&#8221;, it should open in Interface Builder.</p>
<p>4. Drag a UIToolbar to the bottom. We will use the button as a GPS in our next tutorial.</p>
<p>5. Drag MKMapView to the middle of the screen.</p>
<p>6. IB -> save</p>
<p>7. Now we need to reference Mapkit. Go to XCode -> Project -> Edit Active Target &#8220;SimpleMapIB&#8221;. Click the + icon on the bottom left, choose MapKit.framework, then &#8220;Add&#8221;. </p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-1.png" alt="SimpleMapIB-1.png" border="0" width="400" height="421" /></p>
<p>You should see Mapkit added to the frameworks. </p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-2.png" alt="SimpleMapIB-2.png" border="0" width="207" height="105" /></p>
<p>You could also organize XCode&#8217;s left panel by dragging &#8220;MapKit.framework&#8221; to the Frameworks Group.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-3.png" alt="SimpleMapIB-3.png" border="0" width="227" height="132" /></p>
<p>7. Let&#8217;s code SimpleMapIBViewController.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;MapKit/MapKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> SimpleMapIBViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>8. Now back to IB. Click on the &#8220;File&#8217;s Owner&#8221; and you should see your outlets displayed &#8220;Connections Inspector&#8221;. Drag &#8220;mapview&#8221; to MKMapView Control.</p>
<p><a href="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-4.png"><br />
<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-4-sm.png" alt="SimpleMapIB-4-sm.png" border="0" width="300" height="333" /></a><br />
<em>Note: You can click for a bigger image.</em></p>
<p>9. Now to set &#8220;SimpleMapIBViewController&#8221; as the delegate. Click on the MKMapView, it should be highlighted and in the &#8220;Connections Inspector&#8221; notice the &#8220;delegate&#8221; come out in the Outlets. Drag it to the &#8220;Files Owner&#8221; to set &#8220;SimpleMapIBViewController&#8221; as the delegate.</p>
<p><a href="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-5.png" alt="SimpleMapIB-5.png"><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-5-sm.png" alt="SimpleMapIB-5-sm.png" border="0" width="300" height="336" /></a><br />
<em>Note: You can click for a bigger image.</em></p>
<p>10. Now, let&#8217;s test. Hit &#8220;Clean All&#8221; then &#8220;Build and Go&#8221;. You should see something like this..</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-6.png" alt="SimpleMapIB-6.png" border="0" width="150" height="225" /></p>
<p>11. Now to test that the delegate is setup accordingly, we can code on the viewDidLoad.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
    mapview.mapType <span style="color: #002200;">=</span> MKMapTypeSatellite;
&nbsp;
	<span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>12, Now press command-Y for &#8220;Build and Debug&#8221;. We should see a satellite map instead.<br />
<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-7.png" alt="SimpleMapIB-7.png" border="0" width="150" height="226" /></p>
<p>13. That seems a little bit dull, lets add a segmented control so we can switch between maptypes (standard, satellite, hybrid). In IB, drag a UISegmentedControl in the UIToolbar at the bottom. Add another segment, making a total of three. Then change the titles to &#8220;Normal&#8221;, &#8220;Sat&#8221;, &#8220;Hybrid&#8221; respectively.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-8.png" alt="SimpleMapIB-8.png" border="0" width="250" height="389" />.</p>
<p>14. Let&#8217;s code. In the interface, we need to add a method that would be called by the segmentedControl whened the values changed.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;MapKit/MapKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> SimpleMapIBViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
	IBOutlet UISegmentedControl <span style="color: #002200;">*</span>segmentedControlMapType;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UISegmentedControl <span style="color: #002200;">*</span>segmentedControlMapType;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>changeMapType<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Now in IB, click on the &#8220;File&#8217;s Owner&#8221; and you should see your outlets displayed &#8220;Connections Inspector&#8221;. Drag &#8220;segmentedControlMapType&#8221; to the segmented control just like what we did for mapview.</p>
<p>15. In the implementation, we can switch between the segmentIndex and display the corresponding MKMapType.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>changeMapType<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>segmentedControlMapType.selectedSegmentIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		mapview.mapType <span style="color: #002200;">=</span> MKMapTypeStandard;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>segmentedControlMapType.selectedSegmentIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		mapview.mapType <span style="color: #002200;">=</span> MKMapTypeSatellite;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>segmentedControlMapType.selectedSegmentIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		mapview.mapType <span style="color: #002200;">=</span> MKMapTypeHybrid;
	<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>16. Now to hook the IBAction of the UISegmentedControl to the method. In IB, click on the segmented control and in the &#8220;Connections Inspector&#8221;, drag the &#8220;Value Changed&#8221; Event to the &#8220;File&#8217;s Owner&#8221; and choose &#8220;changeMapType&#8221;.</p>
<p><a href="<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-9.png" alt="SimpleMapIB-9.png" border="0" width="600" height="675" />&#8220;><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-9-sm.png" alt="SimpleMapIB-9-sm.png" border="0" width="300" height="338" /></a></p>
<p>17. Now test in the simulator again and the hybrid button should work.<br />
<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-10.png" alt="SimpleMapIB-10.png" border="0" width="323" height="480" /></p>
<p><a href="/wordpress/wp-content/uploads/2009/10/SimpleMapIB.zip" title="SimpleMapIB.zip">Download SimpleMapIB.zip</a></p>
<p>In my next tutorial, I would be hooking up a GPS button which handles location updates using CoreLocation.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/iphone-dev-16-creating-a-mkmapview-using-ib/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>iPhone Note #15: Omnigraffle iPhone Stencils, Screen Mockups via PPT, creating an iPhone interface before actual development</title>
		<link>/wordpress/2009/10/iphone-dev-note-15-omnigraffle-iphone-stencils-screen-mockups-via-ppt-creating-an-iphone-interface-before-actual-development/</link>
		<comments>/wordpress/2009/10/iphone-dev-note-15-omnigraffle-iphone-stencils-screen-mockups-via-ppt-creating-an-iphone-interface-before-actual-development/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 22:41:47 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=559</guid>
		<description><![CDATA[I can not argue enough how valuable an iphone stencil will be in seeing the overall design/flow of an application. I should have done this a long time ago. Well, I am also one of those eager developers who dives right into coding and see how it goes. But after having the fundamentals of iphone]]></description>
			<content:encoded><![CDATA[<p><img src="/wordpress/wp-content/uploads/2009/10/stencil.gif" alt="stencil.gif" border="0" width="350" height="346" /></p>
<p><em><strong>I can not argue enough how valuable an iphone stencil will be in seeing the overall design/flow of an application. I should have done this a long time ago.</strong></em>  </p>
<p>Well, I am also one of those eager developers who dives right into coding and see how it goes. But after having the fundamentals of iphone development, objective-c, and app-store submission, I&#8217;m taking on a different approach by creating screen mockups mainly for the following reasons:</p>
<p>1. Reach out quickly to the client. </p>
<p>2. Provides a bird&#8217;s eye view of the whole application. Provides alternative screens for a better user experience..</p>
<p>3. A follow up on the screen mockups is a powerpoint with actual links to other slides thus mimicing an iphone interface. Note, it is not a complete replica of the simulator but just enough for decision makers to understand what&#8217;s in there.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/stencil-ppt.jpg" alt="stencil-ppt.jpg" border="0" width="400" height="591" /></p>
<p><em>In powerpoint, you can just quickly overlay a transparent polygon on top of the UIButton then attach a hyperlink to another slide.</em></p>
<p>Hope this post helps you even if it&#8217;s not related to coding. On my next post, which is currently buried in my drafts&#8211;hopefully it will not be that long, I learned about integrating with Mobile Advertising Networks.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/iphone-dev-note-15-omnigraffle-iphone-stencils-screen-mockups-via-ppt-creating-an-iphone-interface-before-actual-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATED: Bayanihan iPhone Project for Ondoy. Submitted.</title>
		<link>/wordpress/2009/10/bayanihan-iphone-project-for-ondoy-i-need-pictures/</link>
		<comments>/wordpress/2009/10/bayanihan-iphone-project-for-ondoy-i-need-pictures/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 05:53:45 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=544</guid>
		<description><![CDATA[I am a programmer currently in Melbourne, Australia hoping to raise awareness for the victims affected by typhoon Ondoy (Ketsana-international name). Experiencing a flood is not new to me as I was born and raised in Tumana, Marikina, Metro Manila. I was in primary school, when I could vividly remember my mother cooking and serving]]></description>
			<content:encoded><![CDATA[<p>I am a programmer currently in Melbourne, Australia hoping to raise awareness for the victims affected by typhoon Ondoy (Ketsana-international name). Experiencing a flood is not new to me as I was born and raised in Tumana, Marikina, Metro Manila. I was in primary school, when I could vividly remember my mother cooking and serving porridge to typhoon victims as our backyard was called &#8220;high ground&#8221; since it is near the main road (JP Rizal).</p>
<p>I was in college when Tumana bridge was built and helped me travel from my house to the University. Unfortunately, the river would swell and the flood would swallow the whole bridge after 2-3 days of rain. I called my mother on Sept 27 and was informed the typhoon poured over a whole month of rain in just a few hours! Don&#8217;t worry my mother is fine, however, there are those who are unfortunate enough who desperately call for our help. In my small way by making this application, I would like to show my support for them.</p>
<p>I&#8217;m almost finished with the Bayanihan iPhone project which I worked on over the weekend. It is a very simple app with scrollable images. The server side is almost finished and would display how many supported/downloaded the application in real time. I am hoping to upload the server side to my Linode hosting in the US asap. </p>
<p><b>How can you help?</b> I need pictures! Pictures from Tumana would be greatly appreciated, however, if you have other pictures, please do send them as well. I will be bundling 10 pictures inside the application. Please include your name, with subject: BAYANIHAN pix and send the pictures to my email address: rndguzmanjr@gmail.com</p>
<p>Hopefully I can submit the app to Apple within this week or early next week. Afterwards, we wait for the approval process within 2 weeks. Note, the app would be FREE. </p>
<p><b>UPDATE OCT-05-2009 9:00PM</b><br />
I took some pictures from facebook and dropped it in the project. It would look something like this when it is finished.</p>
<p><a href="/wordpress/wp-content/uploads/2009/10/bayanihan-sample-1.jpg"><img src="/wordpress/wp-content/uploads/2009/10/bayanihan-sample-1-small.jpg" alt="bayanihan-sample-1-small.jpg" border="0" width="800" height="301" /></a></p>
<p><strong>UPDATE OCT-11-2009</strong><br />
- Included proper credits for each photograph.<br />
- Added Admob.<br />
- Created logo, large application icon.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/Icon.png" alt="Icon.png" border="0" width="57" height="57" /></p>
<p><strong>UPDATE OCT-12-2009</strong><br />
Preparing for appstore submission..</p>
<p><strong>UPDATE OCT-13-2009</strong><br />
Submitted in AppStore. Currently, In-Review.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/0.jpg" alt="0.jpg" border="0" width="320" height="460" /></p>
<p><img src="/wordpress/wp-content/uploads/2009/10/8.jpg" alt="8.jpg" border="0" width="320" height="460" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/bayanihan-iphone-project-for-ondoy-i-need-pictures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #14: Drawing a Point, Line, Polygon on top of MKMapview</title>
		<link>/wordpress/2009/10/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/</link>
		<comments>/wordpress/2009/10/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 06:00:49 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=534</guid>
		<description><![CDATA[This is an update to iPhone DevNote #13. This post has solved my zooming/panning problem with a CustomView on top of my MKMapView courtesy of http://spitzkoff.com/craig/?p=108 (Craig&#8217;s blog). The trick here is instead of doing the drawing on the drawRect method of the CustomView, we will use Craig&#8217;s methodology to use the drawRect method of]]></description>
			<content:encoded><![CDATA[<p>This is an update to <a href="">iPhone DevNote #13.</a> This post has solved my zooming/panning problem with a CustomView on top of my MKMapView courtesy of <a href="http://spitzkoff.com/craig/?p=108">http://spitzkoff.com/craig/?p=108 (Craig&#8217;s blog)</a>.  </p>
<p>The trick here is instead of doing the drawing on the drawRect method of the CustomView, we will use <a href="http://spitzkoff.com/craig/?p=108">Craig&#8217;s methodology</a> to use the drawRect method of a custom MKAnnotationView.  Note, that he also used an internal view and made clipsToBounds = NO, this way we can draw the whole geometry on top of MKMapView not just a portion of it. The end result is the shape (polygon in this example) is below the added pins.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/polygon_on_top_mapview.png" alt="polygon_on_top_mapview.png" border="0" width="250" height="372" /></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> LinePolygonAnnotationInternalView <span style="color: #002200;">:</span> UIView
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// line view which added this as a subview. </span>
	LinePolygonAnnotationView<span style="color: #002200;">*</span> _mainView;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> LinePolygonAnnotationView<span style="color: #002200;">*</span> mainView;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> LinePolygonAnnotationInternalView
&nbsp;
<span style="color: #a61390;">@synthesize</span> mainView <span style="color: #002200;">=</span> _mainView;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init
<span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	self.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
	self.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span> rect
<span style="color: #002200;">&#123;</span>
	GeometryAnnotation<span style="color: #002200;">*</span> myAnnotation <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>GeometryAnnotation<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>self.mainView.annotation;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// only draw our lines if we're not int he moddie of a transition and we </span>
	<span style="color: #11740a; font-style: italic;">// acutally have some points to draw. </span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>self.hidden <span style="color: #002200;">&amp;&amp;</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">!=</span> myAnnotation.points <span style="color: #002200;">&amp;&amp;</span> myAnnotation.points.count &gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; 
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Drawing lines with a white stroke color</span>
		CGContextSetRGBStrokeColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Draw them with a 2.0 stroke width so they are a bit more visible.</span>
		CGContextSetLineWidth<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>;		
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypePolygon<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			CGContextSetRGBFillColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Draw them with a 2.0 stroke width so they are a bit more visible.</span>
		CGContextSetLineWidth<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> idx <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; idx &lt; myAnnotation.points.count; idx<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			CLLocation<span style="color: #002200;">*</span> location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myAnnotation.points objectAtIndex<span style="color: #002200;">:</span>idx<span style="color: #002200;">&#93;</span>;
			CGPoint point <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.mainView.mapView convertCoordinate<span style="color: #002200;">:</span>location.coordinate toPointToView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Point: %lf, %lf&quot;</span>, point.x, point.y<span style="color: #002200;">&#41;</span>;
&nbsp;
			<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>idx <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
			<span style="color: #002200;">&#123;</span>
				<span style="color: #11740a; font-style: italic;">// move to the first point</span>
				CGContextMoveToPoint<span style="color: #002200;">&#40;</span>context, point.x, point.y<span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">else</span>
			<span style="color: #002200;">&#123;</span>
				CGContextAddLineToPoint<span style="color: #002200;">&#40;</span>context, point.x, point.y<span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#125;</span>
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypeLine<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			CGContextStrokePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
		<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypePolygon<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			CGContextClosePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
			CGContextDrawPath<span style="color: #002200;">&#40;</span>context, kCGPathFillStroke<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc
<span style="color: #002200;">&#123;</span>
	self.mainView <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> LinePolygonAnnotationView
&nbsp;
<span style="color: #a61390;">@synthesize</span> mapView <span style="color: #002200;">=</span> _mapView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>frame <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		self.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// do not clip the bounds. We need the LinePolygonAnnotationInternalView to be able to render the whole line/polygon, regardless of where the</span>
		<span style="color: #11740a; font-style: italic;">// actual annotation view is displayed. </span>
		self.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// create the internal line view that does the rendering of the line. </span>
		_internalView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>LinePolygonAnnotationInternalView alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
		_internalView.mainView <span style="color: #002200;">=</span> self;
&nbsp;
		<span style="color: #002200;">&#91;</span>self addSubview<span style="color: #002200;">:</span>_internalView<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setMapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> mapView
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_mapView release<span style="color: #002200;">&#93;</span>;
	_mapView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mapView retain<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self regionChanged<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> regionChanged
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Region Changed&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// move the internal line view. </span>
	CGPoint origin <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	origin <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_mapView convertPoint<span style="color: #002200;">:</span>origin toView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
	_internalView.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>origin.x, origin.y, _mapView.frame.size.width, _mapView.frame.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>_internalView setNeedsDisplay<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc 
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_mapView release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>_internalView release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>I extended the class above to be able to draw both lines and polygons by checking a property (geometryType) of the GeometryAnnotation. If the geometryType is a line, then just stroke the path. However, if the geometryType is a polygon, then close the path and fill it.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypeLine<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
	CGContextStrokePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypePolygon<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
	CGContextClosePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
	CGContextDrawPath<span style="color: #002200;">&#40;</span>context, kCGPathFillStroke<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And here is the GeometryAnnotation class. Most of the code is from <a href="http://spitzkoff.com/craig/?p=108">Craig</a>, i just added the geometryType property:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//  Created by Craig on 8/18/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright Craig Spitzkoff 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;GeometryAnnotation.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> GeometryAnnotation
<span style="color: #a61390;">@synthesize</span> coordinate <span style="color: #002200;">=</span> _center;
<span style="color: #a61390;">@synthesize</span> points <span style="color: #002200;">=</span> _points; 
<span style="color: #a61390;">@synthesize</span> annotationID;
<span style="color: #a61390;">@synthesize</span> geometryType;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithPoints<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> points withGeometry<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>GeometryType<span style="color: #002200;">&#41;</span>geomType
<span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
&nbsp;
	geometryType <span style="color: #002200;">=</span> geomType;
&nbsp;
	_points <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> initWithArray<span style="color: #002200;">:</span>points<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// create a unique ID for this line so it can be added to dictionaries by this key. </span>
	self.annotationID <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%p&quot;</span>, self<span style="color: #002200;">&#93;</span>;
&nbsp;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// determine a logical center point for this line based on the middle of the lat/lon extents.</span>
	<span style="color: #a61390;">double</span> maxLat <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">91</span>;
	<span style="color: #a61390;">double</span> minLat <span style="color: #002200;">=</span>  <span style="color: #2400d9;">91</span>;
	<span style="color: #a61390;">double</span> maxLon <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">181</span>;
	<span style="color: #a61390;">double</span> minLon <span style="color: #002200;">=</span>  <span style="color: #2400d9;">181</span>;
&nbsp;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>CLLocation<span style="color: #002200;">*</span> currentLocation <span style="color: #a61390;">in</span> _points<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		CLLocationCoordinate2D coordinate <span style="color: #002200;">=</span> currentLocation.coordinate;
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.latitude &gt; maxLat<span style="color: #002200;">&#41;</span>
			maxLat <span style="color: #002200;">=</span> coordinate.latitude;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.latitude &lt; minLat<span style="color: #002200;">&#41;</span>
			minLat <span style="color: #002200;">=</span> coordinate.latitude;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.longitude &gt; maxLon<span style="color: #002200;">&#41;</span>
			maxLon <span style="color: #002200;">=</span> coordinate.longitude;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.longitude &lt; minLon<span style="color: #002200;">&#41;</span>
			minLon <span style="color: #002200;">=</span> coordinate.longitude; 
	<span style="color: #002200;">&#125;</span>
&nbsp;
	_span.latitudeDelta <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>maxLat <span style="color: #002200;">+</span> <span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>minLat <span style="color: #002200;">+</span> <span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span>;
	_span.longitudeDelta <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>maxLon <span style="color: #002200;">+</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>minLon <span style="color: #002200;">+</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// the center point is the average of the max and mins</span>
	_center.latitude <span style="color: #002200;">=</span> minLat <span style="color: #002200;">+</span> _span.latitudeDelta <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>;
	_center.longitude <span style="color: #002200;">=</span> minLon <span style="color: #002200;">+</span> _span.longitudeDelta <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Found center of new Annotation at %lf, %ld&quot;</span>, _center.latitude, _center.longitude<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>MKCoordinateRegion<span style="color: #002200;">&#41;</span> region
<span style="color: #002200;">&#123;</span>
	MKCoordinateRegion region;
	region.center <span style="color: #002200;">=</span> _center;
	region.span <span style="color: #002200;">=</span> _span;
&nbsp;
	<span style="color: #a61390;">return</span> region;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_points release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Now that we have a way to draw a line/polygon as a custom MKAnnotationView, we need a custom TouchView (GeometryTouchView) which could accept the touch events. </p>
<p>For example, if the user wants to draw a line geometry, the GeometryTouchView would accept touch events from the user and add a point as a PointAnnotation in the Map.  Succeeding points would be added to an array. For every point added, the MKAnnotationView drawRects method connects the points to produce a line.  The MKAnnotationView is now added to the map. </p>
<p>Once the geometry is added as an annotation, the custom TouchView is hidden. This way we have access (panning/zooming) to the mapview.  If we make a pan or a zoom, the region changes, thus we need to redraw the shape of the annotation again.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView regionWillChangeAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>currentAnnotationView <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;regionWillChangeAnimated&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		currentAnnotationView.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView regionDidChangeAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>currentAnnotationView <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;regionDidChangeAnimated&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		currentAnnotationView.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
		<span style="color: #002200;">&#91;</span>currentAnnotationView regionChanged<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> regionChanged
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Region Changed&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// move the internal line view. </span>
	CGPoint origin <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	origin <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_mapView convertPoint<span style="color: #002200;">:</span>origin toView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
	_internalView.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>origin.x, origin.y, _mapView.frame.size.width, _mapView.frame.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>_internalView setNeedsDisplay<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The resulting image is now:<br />
<img src="/wordpress/wp-content/uploads/2009/10/polygon_small_on_top_of_mapview.png" alt="polygon_small_on_top_of_mapview.png" border="0" width="250" height="372" /></p>
<p>Download the <a href="/wordpress/wp-content/uploads/2009/10/DrawMap.zip" title="DrawMap.zip">DrawMap.zip</a> code.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>iPhone Note #13: Drawing Point, Line, Polygon on top of MKMapview</title>
		<link>/wordpress/2009/09/iphone-devnote-13-drawing-point-line-polygon-on-top-of-mkmapview/</link>
		<comments>/wordpress/2009/09/iphone-devnote-13-drawing-point-line-polygon-on-top-of-mkmapview/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 00:10:36 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=529</guid>
		<description><![CDATA[Now I have a reason to study Quartz2D! I am trying to draw a point, line and polygon on top of MKMapview. I will list below important links for reference: 1. Always use Apple&#8217;s iPhone OS Reference Library Documentation.. Under &#8220;Topics&#8221; > &#8220;Graphics &#038; Animation&#8221; you will find a lot of references, guides and sample]]></description>
			<content:encoded><![CDATA[<p>Now I have a reason to study Quartz2D! I am trying to draw a point, line and polygon on top of MKMapview. I will list below important links for reference:</p>
<p>1. Always use Apple&#8217;s <a href="http://developer.apple.com/iphone/library/navigation/index.html">iPhone OS Reference Library Documentation.</a>. Under &#8220;Topics&#8221; > &#8220;Graphics &#038; Animation&#8221; you will find a lot of references, guides and sample code.</p>
<p>2. Start out with the <a href="">Getting Started with Graphics and Animation. </a> Note, if you ever read the line below and try to find Finger Sketch, please drop me a comment. I could not find it anywhere!</p>
<blockquote><p><cite>&#8220;Next, examine the Finger Sketch sample code in Xcode.&#8221;</cite></p></blockquote>
<p>3. <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/GraphicsandDrawing/GraphicsandDrawing.html#//apple_ref/doc/uid/TP40007072-CH10-SW1">iPhone Application Programming Guide: Graphics and Drawing</a>.</p>
<p>4. Note: I haven&#8217;t read everything on <a href="http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html">Quartz 2D Programming Guide</a>, but I went straight to the <em>Paths</em> Section.</p>
<p>5. Lets look at some sample codes, especially the QuartzDemo.</p>
<p>6. Now, I presume you know IB, add a MKMapView and a UIToolbar at the bottom. Add four UIBarButtonItems for: Map, Point, Line, Polygon. Set MKMapView&#8217;s delegate to the File&#8217;s Owner. Hook up the UIBarButtonItem IBOutlets to your buttons, so we can change the appearance of the buttons when pressed. Lastly, hook up our IBAction methods for each button.</p>
<p>The Map button allows to pan/zoom on the Map. If any of the three geometry buttons (PT, LN, PG) is pressed, we unhide the GeometryView(which is a UIView) to allow touchEvents to proceed.</p>
<p>TO DO: Watch out for this segment as I will update it with code later.</p>
<p>7. Now to draw a line, we implement the code below in our GeometryView.drawRect method. As we loop through each Pin, we add a line to the point. Afterwards, we stroke the path, thus drawing the lines.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Drawing lines with a white stroke color</span>
CGContextSetRGBStrokeColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Draw them with a 2.0 stroke width so they are a bit more visible.</span>
CGContextSetLineWidth<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>pinFactory actualPinCount<span style="color: #002200;">&#93;</span> &gt; <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
&nbsp;
	Pin <span style="color: #002200;">*</span>pin1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>Pin <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>pinFactory pinArray<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
	CGPoint pt1 <span style="color: #002200;">=</span> pin1.touchLocation;
	CGContextMoveToPoint<span style="color: #002200;">&#40;</span>context, pt1.x, pt1.y<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>; i &lt; <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>pinFactory actualPinCount<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		Pin <span style="color: #002200;">*</span>pin2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>Pin <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>pinFactory pinArray<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		CGPoint pt2 <span style="color: #002200;">=</span> pin2.touchLocation;
		CGContextAddLineToPoint<span style="color: #002200;">&#40;</span>context, pt2.x, pt2.y<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	CGContextStrokePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2009/09/line.png" alt="line.png" border="0" width="320" height="481" /></p>
<p>8. To draw a polygon, we close the path of lines then fill the polygon.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextClosePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextDrawPath<span style="color: #002200;">&#40;</span>context, kCGPathFillStroke<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2009/09/poly.png" alt="poly.png" border="0" width="320" height="481" /></p>
<p>Note: I&#8217;ll try to post the sample code when I have time. I&#8217;m trying to minimize blogging to 10 mins per post as my work tasks/personal development tasks is piling up&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-devnote-13-drawing-point-line-polygon-on-top-of-mkmapview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone Note #12: Adding a UIButton on a UITableViewCell (Borderless)</title>
		<link>/wordpress/2009/09/iphone-note-12-adding-a-uibutton-on-a-uitableviewcell-borderless/</link>
		<comments>/wordpress/2009/09/iphone-note-12-adding-a-uibutton-on-a-uitableviewcell-borderless/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 00:58:08 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=523</guid>
		<description><![CDATA[1. Im trying to add two UIbuttons to a UITableViewCell, similar to the contacts app. Creating the UIButtons programmatically and adding them to the cell&#8217;s subview is trivial. However the interface is a bit different from the contacts app, see image here&#8230; cell = &#91;&#91;&#91;UITableViewCell alloc&#93; initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@&#34;ButtonCell&#34;&#93; autorelease&#93;; &#160; UIButton *buttonLeft = &#91;UIButton buttonWithType:UIButtonTypeRoundedRect&#93;;]]></description>
			<content:encoded><![CDATA[<p>1. Im trying to add two UIbuttons to a UITableViewCell, similar to the contacts app. Creating the UIButtons programmatically and adding them to the cell&#8217;s subview is trivial. However the interface is a bit different from the contacts app, see image here&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/UIButtons-dirty.png" alt="UIButtons-dirty.png" border="0" width="320" height="68" /></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ButtonCell&quot;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonLeft <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Left&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 10.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonRight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Right&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 165.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonLeft<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonRight<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>2. So to make the background the same as <em>UITableViewStyleGrouped</em>, we can implement:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor groupTableViewBackgroundColor<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>But I could still see the border of the UITableViewCell.. see image below&#8230;<br />
<img src="/wordpress/wp-content/uploads/2009/09/UIButtons-not-so-clean.png" alt="UIButtons-not-so-clean.png" border="0" width="318" height="61" /></p>
<p>3. The crux of it was to implement a UIView, set the background as <em>UITableViewStyleGrouped</em> and add that as a cell&#8217;s backgroundView.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ButtonCell&quot;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
UIView <span style="color: #002200;">*</span>backgroundView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 320.0f, 44.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
backgroundView.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor groupTableViewBackgroundColor<span style="color: #002200;">&#93;</span>;
&nbsp;
cell.backgroundView <span style="color: #002200;">=</span> backgroundView;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonLeft <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Left&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 10.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonRight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Right&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 165.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonLeft<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonRight<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>backgroundView release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Now the interface is a whole lot cleaner and the resulting image is better&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/UIButtons-clean.png" alt="UIButtons-clean.png" border="0" width="320" height="62" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-note-12-adding-a-uibutton-on-a-uitableviewcell-borderless/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #11: Unit Testing</title>
		<link>/wordpress/2009/09/iphone-note-11-unit-testing/</link>
		<comments>/wordpress/2009/09/iphone-note-11-unit-testing/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 05:31:43 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">/wordpress/?p=518</guid>
		<description><![CDATA[Test first, develop later! That&#8217;s the greeting when you visit OCUnit, similar to JUnit. Note that for this tutorial, you do not need to install OCUnit as it comes &#8220;built-in&#8221; in XCode as of v2.1. 1. Create a new iPhone Window-based application project &#8220;SampleTest&#8221;. 2. Our subject for testing is Converter.m which converts kilometers to]]></description>
			<content:encoded><![CDATA[<p>Test first, develop later! That&#8217;s the greeting when you visit <a href="http://www.sente.ch/software/ocunit/">OCUnit</a>, similar to JUnit. Note that for this tutorial, you do not need to install OCUnit as it comes &#8220;built-in&#8221; in XCode as of v2.1.</p>
<p>1. Create a new iPhone Window-based application project &#8220;SampleTest&#8221;.</p>
<p>2. Our subject for testing is Converter.m which converts kilometers to meters. Let&#8217;s implement an incorrect conversion by specifying 1km = 100 meters (should be 1000 meters) so we can see that the unit test captures it below&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Converter.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> Converter
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>convertKilometersToMeters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>km<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> km <span style="color: #002200;">*</span> <span style="color: #2400d9;">100</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>3. Add another target &#8220;UnitTests&#8221;. Right click on Targets -> Add -> New Target&#8230; -> Choose Unit Test Bundle. </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-bundle.png" alt="unit-test-bundle.png" border="0" width="400" height="143" /></p>
<p>4. Name it &#8220;UnitTests&#8221;. After hitting submit, you will be presented with the project settings for &#8220;UnitTests&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-name2.png" alt="unit-test-name2.png" border="0" width="200" height="90" /></p>
<p>5. Go to the General Tab -> Click on the &#8220;+&#8221; icon above &#8220;Linked Libraries&#8221;. Choose &#8220;SampleTest&#8221; as the application we have direct dependency with.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-dependency-3.png" alt="unit-test-dependency-3.png" border="0" width="300" height="452" /></p>
<p>6. Close the Settings. To check, navigate under &#8220;Groups &#038; Files&#8221; -> Targets. You should see the SampleTest Application Icon just below &#8220;UnitTests&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-tree-4.png" alt="unit-test-tree-4.png" border="0" width="225" height="191" /></p>
<p>7. Right Click on &#8220;Sample Test&#8221; -> Add -> New File&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-class5.png" alt="unit-test-class5.png" border="0" width="400" height="300" /></p>
<p>8. Name the file &#8220;ConverterTest. Don&#8217;t forget to also create the header file (default). Specify it also in a different directory under &#8220;Location&#8221;. Then check the UnitTests as the &#8220;Targets&#8221;. When you hit &#8220;Finish&#8221; it will ask you to create the folder &#8220;Tests&#8221;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-class6.png" alt="unit-test-class6.png" border="0" width="400" height="294" /></p>
<p>Tip: Keep things organize and put it under a &#8220;Tests&#8221; Group. Right Click on &#8220;Sample Test&#8221; -> Add -> New Group&#8230; Name it &#8220;Tests&#8221;, then drag the files (ConverterTest.h and ConverterTest.m) into that group.</p>
<p>9. Open up ConverterTest.h and notice that &#8220;SenTestingKit.h&#8221; is already imported. Now let&#8217;s add method testKilometersToMeters as shown below. Test methods usually start out with a <em>test</em> prefix.</p>
<p>In the implementation, let&#8217;s import Converter.h and use STAssertTrue. To test the convertKilometersToMeters method, we are asserting that the result should be 1000. If not, then we should know! That is why we are writing a unit test for.. making sure that our implementation doesn&#8217;t break.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;ConverterTest.h&quot;</span>
<span style="color: #6e371a;">#import &quot;Converter.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> ConverterTest
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testKilometersToMeters<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> km <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;
	Converter <span style="color: #002200;">*</span>converter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Converter alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">int</span> meters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>converter convertKilometersToMeters<span style="color: #002200;">:</span>km<span style="color: #002200;">&#93;</span>;
	STAssertTrue<span style="color: #002200;">&#40;</span>meters <span style="color: #002200;">==</span> <span style="color: #2400d9;">1000</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;converting %d km to meters should equal 1000, instead received %d&quot;</span>, km, meters<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>12. Now, before we build our target &#8220;UnitTests&#8221;, we need to include additional class references from our application. Drag Converter.m to the &#8220;Compile Sources&#8221; under UnitTests.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-drag7.png" alt="unit-test-drag7.png" border="0" width="147" height="400" /></p>
<p>13. Now we can build. There are many ways to do this. My preference is to do a clean build when testing. Right Click on Sample Test then choose &#8220;Clean SampleTest&#8221;. Afterwards choose &#8220;Build SampleTest&#8221;.  </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-build8.png" alt="unit-test-build8.png" border="0" width="200" height="154" /></p>
<p>If you have a succesful build for SampleTest, lets do the same for our &#8220;UnitTests&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-build9.png" alt="unit-test-build9.png" border="0" width="230" height="236" /></p>
<p>13. Here&#8217;s the crux of it. Notice the <em>error</em> in your &#8220;Build Results&#8221;?</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/Users/rupert/projects/iphone/SampleTest/Tests/ConverterTest.m:18: error: -[ConverterTest testKilometersToMeters] : &quot;meters == 1000&quot; should be true. converting 1 km to meters should equal 1000, instead received 100</pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-results.png" alt="unit-test-results.png" border="0" width="400" height="422" /></p>
<p>Now changing the correct implementation of convertKilometersToMeters will put the error away and you will have a successful build.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>convertKilometersToMeters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>km<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> km <span style="color: #002200;">*</span> <span style="color: #2400d9;">1000</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>14. Look up the assert methods from SenTest.h.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/NSObject.h&gt;</span>
<span style="color: #6e371a;">#import &quot;SenTest.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#define STAssertNil(a1, description, ...)</span>
<span style="color: #6e371a;">#define STAssertNotNil(a1, description, ...)</span>
<span style="color: #6e371a;">#define STAssertTrue(expression, description, ...)</span>
<span style="color: #6e371a;">#define STAssertFalse(expression, description, ...)</span>
<span style="color: #6e371a;">#define STAssertEqualObjects(a1, a2, description, ...)</span>
<span style="color: #6e371a;">#define STAssertEquals(a1, a2, description, ...)</span>
<span style="color: #6e371a;">#define STAssertEqualsWithAccuracy(left, right, accuracy, description, ...)</span>
<span style="color: #6e371a;">#define STAssertFalseNoThrow(expression, description, ...)</span>
....</pre></div></div>

<p>References:</p>
<p><a href="http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/UnitTesting/Articles/CreatingTests.html">http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/UnitTesting/Articles/CreatingTests.html</a></p>
<p><a href="http://developer.apple.com/tools/unittest.html">http://developer.apple.com/tools/unittest.html</a></p>
<p>Download: <a href="/wordpress/wp-content/uploads/2009/09/SampleTest.zip" title="SampleTest.zip">SampleTest.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-note-11-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #10: Creating Custom Settings</title>
		<link>/wordpress/2009/09/iphone-note-10-creating-custom-settings/</link>
		<comments>/wordpress/2009/09/iphone-note-10-creating-custom-settings/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 04:47:49 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=499</guid>
		<description><![CDATA[1. Create a directory on your desktop, name it &#8220;Foo&#8221; 2. Download this Sample_plist.txt and place it inside foo. Name it as Root.plist Foo/ Foo/Root.plist 3. Rename Foo to Settings.bundle Settings.bundle/ Settings.bundle/Root.plist 4. Drag it to your project. 5. To retrieve a value from the settings.. For example, if we want to retrieve if the]]></description>
			<content:encoded><![CDATA[<p><img src="/wordpress/wp-content/uploads/2009/09/settings-overview.gif" alt="settings-overview.gif" border="0" width="400" height="176" /></p>
<p>1. Create a directory on your desktop, name it &#8220;Foo&#8221;</p>
<p>2. Download this <a href="/wordpress/wp-content/uploads/2009/09/Sample_plist.txt" title="Sample_plist.txt">Sample_plist.txt</a> and place it inside foo. Name it as Root.plist</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Foo<span style="color: #000000; font-weight: bold;">/</span>
Foo<span style="color: #000000; font-weight: bold;">/</span>Root.plist</pre></div></div>

<p>3. Rename Foo to Settings.bundle</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Settings.bundle<span style="color: #000000; font-weight: bold;">/</span>
Settings.bundle<span style="color: #000000; font-weight: bold;">/</span>Root.plist</pre></div></div>

<p>4. Drag it to your project.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/settings-bundle.gif" alt="settings-bundle.gif" border="0" width="234" height="187" /></p>
<p>5. To retrieve a value from the settings.. For example, if we want to retrieve if the <em>&#8220;enabled&#8221;</em> switch is on or off?</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSUserDefaults</span> <span style="color: #002200;">*</span>defaults <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSUserDefaults</span> standardUserDefaults<span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">BOOL</span> b <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>defaults boolForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;enabled_preference&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-note-10-creating-custom-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #9: Sending or Uploading over HTTP Post</title>
		<link>/wordpress/2009/08/iphone-note-8-sending-or-uploading-over-http-post/</link>
		<comments>/wordpress/2009/08/iphone-note-8-sending-or-uploading-over-http-post/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 06:55:11 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=100</guid>
		<description><![CDATA[In this tutorial, we would use an Objective-C Library: ASIHTTPRequest, which abstracts the complexities of using NSURLConnection 1. Download the latest build. 2. Create a new view based project &#8220;HTTPTest&#8221;. XCode -&#62; File -&#62; New Project -&#62; View-based Application 3. Add the ff frameworks: CFNetwork, SystemConfiguration, and libz (compression library). For more details, follow these]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we would use an <a href="http://allseeing-i.com/ASIHTTPRequest/">Objective-C Library: ASIHTTPRequest</a>, which abstracts the complexities of using <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html">NSURLConnection</a></p>
<p><img src="/wordpress/wp-content/uploads/2009/08/http-final.gif" border="0" alt="http-final.gif" width="223" height="334" /><span id="more-375"></span></p>
<p>1. Download the latest <a href="http://allseeing-i.com/ASIHTTPRequest/">build</a>.</p>
<p>2. Create a new view based project &#8220;HTTPTest&#8221;. XCode -&gt; File -&gt; New Project -&gt; View-based Application</p>
<p>3. Add the ff frameworks: CFNetwork, SystemConfiguration, and libz (compression library). For more details, follow these <a href="http://allseeing-i.com/ASIHTTPRequest/Setup-instructions">instructions</a></p>
<p>4. In IB, let&#8217;s add two UIButton&#8217;s, a UITextView *textView and a UIProgressView *progressView. The two buttons is for HTTP URL and HTTP FORM requests. The textView will display the response of the HTTP request. While the progressView is for displaying the uploading progress. It should look something similar to the image below&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/http-1.gif" border="0" alt="http-1.gif" width="323" height="504" /></p>
<p>5. Here is the interface:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
&nbsp;
<span style="color: #a61390;">@interface</span> HTTPTestViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet UIButton <span style="color: #002200;">*</span>buttonSubmitURL;
	IBOutlet UIButton <span style="color: #002200;">*</span>buttonSubmitForm;
	IBOutlet UITextView <span style="color: #002200;">*</span>textView;
	IBOutlet UIProgressView <span style="color: #002200;">*</span>progressView;
&nbsp;
	<span style="color: #400080;">NSOperationQueue</span> <span style="color: #002200;">*</span>queue;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIButton <span style="color: #002200;">*</span>buttonSubmitURL;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIButton <span style="color: #002200;">*</span>buttonSubmitForm;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIProgressView <span style="color: #002200;">*</span>progressView;
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UITextView <span style="color: #002200;">*</span>textView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>submitURLPressed;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>submitFormPressed;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>6. In IB, hook up the IBAction method&#8217;s from the &#8220;Touch Up Inside&#8221; events for each button.</p>
<p>URL Button  -&gt; Touch Up Inside -&gt; submitURLPressed<br />
Form Button -&gt; Touch Up Inside -&gt; submitFormPressed</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/http-2.gif" border="0" alt="http-2.gif" width="291" height="283" /></p>
<p>7. Let&#8217;s do the URL first. From the code snippet below, notice that it is a UI blocking call as the call is synchronous. From the <a href="http://allseeing-i.com/ASIHTTPRequest/How-to-use">&#8220;How to use it&#8221;</a> section of ASI&#8217;s website:</p>
<blockquote><p>The simplest way to use ASIHTTPRequest. Sending the start message will execute the request in the same thread, and return control when it has completed (successfully or otherwise).</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>submitURLPressed<span style="color: #002200;">&#123;</span>
	textView.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;
&nbsp;
	<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://192.168.1.188/iphone/test.cfm&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	ASIHTTPRequest <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ASIHTTPRequest alloc<span style="color: #002200;">&#93;</span> initWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>request start<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request error<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>error<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>response <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request responseString<span style="color: #002200;">&#93;</span>;
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Result string: %@&quot;</span>, response<span style="color: #002200;">&#41;</span>;
&nbsp;
		textView.text <span style="color: #002200;">=</span> response;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>8. Now let&#8217;s do an asynchronous request so the UI can respond using the progressView. Implement the code snippet below for submitFormPressed. Notice, that I am using an image (http_test.gif) which is bundled up in the application. After creating the *request, I made HTTPTestViewController as the delegate. Therefore we need to implement methods requestDone and requestWentWrong in step [9].</p>
<p>To add a form value, simple do <code>[request setPostValue:@"rupert" forKey:@"name"];</code></p>
<p>To add a file, simple pass the NSString path to setFile, i.e:<br />
<code>[request setFile:imagePath1 forKey:@"file"];</code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>submitFormPressed<span style="color: #002200;">&#123;</span>
	queue <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSOperationQueue</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>queue setMaxConcurrentOperationCount<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>imagePath1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> resourcePath<span style="color: #002200;">&#93;</span> stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http_test.gif&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	textView.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>progressView setProgress<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://192.168.1.193/dbydsms/upload.aspx&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	ASIFormDataRequest <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ASIFormDataRequest alloc<span style="color: #002200;">&#93;</span> initWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>request setDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setDidFinishSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>requestDone<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setDidFailSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>requestWentWrong<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>request setPostValue<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;rupert&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;name&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>request setFile<span style="color: #002200;">:</span>imagePath1 forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;file&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>request setUploadProgressDelegate<span style="color: #002200;">:</span>progressView<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>queue addOperation<span style="color: #002200;">:</span>request<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>9. Conforming to the delegate&#8217;s methods&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>requestDone<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ASIHTTPRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Value: %f&quot;</span>, <span style="color: #002200;">&#91;</span>progressView progress<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request error<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>error<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>response <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request responseString<span style="color: #002200;">&#93;</span>;
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Result string: %@&quot;</span>, response<span style="color: #002200;">&#41;</span>;
&nbsp;
		textView.text <span style="color: #002200;">=</span> response;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>requestWentWrong<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ASIHTTPRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request error<span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;error: %@&quot;</span>, error<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>10. For the upload.aspx,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        HttpFileCollection uploadFiles <span style="color: #008000;">=</span> Request.<span style="color: #0000FF;">Files</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Loop over the uploaded files and save to disk.</span>
        <span style="color: #FF0000;">int</span> i<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span>i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> uploadFiles.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            HttpPostedFile postedFile <span style="color: #008000;">=</span> uploadFiles<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Access the uploaded file's content in-memory:</span>
            <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span>.<span style="color: #0000FF;">Stream</span> inStream <span style="color: #008000;">=</span> postedFile.<span style="color: #0000FF;">InputStream</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> fileData <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span>postedFile.<span style="color: #0000FF;">ContentLength</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            inStream.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span>fileData, <span style="color: #FF0000;">0</span>, postedFile.<span style="color: #0000FF;">ContentLength</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Save the posted file in our &quot;data&quot; virtual directory.</span>
            postedFile.<span style="color: #0000FF;">SaveAs</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;E:<span style="color: #008080; font-weight: bold;">\\</span>RupertWork<span style="color: #008080; font-weight: bold;">\\</span>wwwroot<span style="color: #008080; font-weight: bold;">\\</span>project<span style="color: #008080; font-weight: bold;">\\</span>uploads<span style="color: #008080; font-weight: bold;">\\</span>&quot;</span> <span style="color: #008000;">+</span> postedFile.<span style="color: #0000FF;">FileName</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-8-sending-or-uploading-over-http-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Quick Tip #2: Creating Objective-C Class Diagrams Instantly</title>
		<link>/wordpress/2009/08/iphone-quick-tip-1-creating-objective-c-class-diagrams-instantly/</link>
		<comments>/wordpress/2009/08/iphone-quick-tip-1-creating-objective-c-class-diagrams-instantly/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 23:58:02 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=95</guid>
		<description><![CDATA[Omnigraffle provides a quick and dirty class diagram when you open your XCode projects. Very cool and saves you a lot of time than using VISIO. 1. Simple go to Omnigraffle -&#62; File -&#62; Open. Navigate to your_project.xcodeproj 2. A popup like below will even let you configure if you want to map out the]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.omnigroup.com/applications/OmniGraffle/">Omnigraffle</a> provides a quick and dirty class diagram when you open your XCode projects. Very cool and saves you a lot of time than using VISIO.<span id="more-371"></span></p>
<p>1. Simple go to Omnigraffle -&gt; File -&gt; Open. Navigate to your_project.xcodeproj</p>
<p>2. A popup like below will even let you configure if you want to map out the protocols and categories. Normally, the ivars and methods are checked by default.</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/omni-xcode.gif" alt="omni-xcode.gif" border="0" width="390" height="232" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-quick-tip-1-creating-objective-c-class-diagrams-instantly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #8: Exporting Oracle to SQLite3</title>
		<link>/wordpress/2009/08/iphone-note-7-exporting-oracle-to-sqlite3/</link>
		<comments>/wordpress/2009/08/iphone-note-7-exporting-oracle-to-sqlite3/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 12:31:09 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=92</guid>
		<description><![CDATA[Since I&#8217;ve been working most of my time with iPhone Dev for the last couple of months, I thought it will be worthwile to post how to import files to SQLite3. In a nutshell, use MesaSQLite&#8217;s IMPORT function. It will save you a lot of time. Now it is up to you how to export]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve been working most of my time with iPhone Dev for the last couple of months, I thought it will be worthwile to post how to import files to SQLite3. In a nutshell, use  <a href="http://www.mesamysql.com/?realmesa_home">MesaSQLite&#8217;s</a> IMPORT function. It will save you a lot of time. Now it is up to you how to export into a CSV or TAB delimited file. For Oracle, I used <a href="http://www.oracle.com/technology/products/database/sql_developer/index.html">SQLDeveloper</a>. For other databases, such as MySQL or Postgres, I&#8217;ve used <a href="http://www.navicat.com">Navicat.</a><span id="more-369"></span></p>
<p>1. Using <a href="http://www.oracle.com/technology/products/database/sql_developer/index.html">SQLDeveloper</a> -&gt; Right Click on the Table from the left pane -&gt; Export</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/oracle-sqldeveloper-left.gif" alt="oracle-sqldeveloper-left.gif" border="0" width="278" height="377" /></p>
<p><img src="/wordpress/wp-content/uploads/2009/08/oracle-sqldeveloper.gif" alt="oracle-sqldeveloper.gif" border="0" width="467" height="409" /></p>
<p>2. Choose TEXT since we are going to use that when importing using <a href="http://www.mesamysql.com/?realmesa_home">MesaSQLite.</a> Note, SQLDeveloper does not export CLOB columns. You need to change your column from CLOB to VARCHAR. A workaround is to add a column and then update that column aferwards.</p>
<pre>
ALTER TABLE poi ADD en_desc VARCHAR(2000);
UPDATE poi SET en_desc = en_short_desc;
</pre>
<p>3. In <a href="http://www.mesamysql.com/?realmesa_home">MesaSQLite,</a> FILE -&gt; IMPORT -&gt; CSV/TAB</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/mesa-1.gif" alt="mesa-1.gif" border="0" width="274" height="127" /></p>
<p>4. Choose the table which you want to import.</p>
<p>5. Choose your exported TAB delimited file from SQLDeveloper.</p>
<p>6. Afterwards, map the corresponding fields to your database. Note, that I added an extra column &#8220;dummy&#8221; in the file because it seems I can only match n-1 columns, thus the extra column.</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/mesa-2.gif" alt="mesa-2.gif" border="0" width="344" height="349" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-7-exporting-oracle-to-sqlite3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #7: TableView as Single Selections</title>
		<link>/wordpress/2009/08/iphone-note-6-tableview-as-single-selections/</link>
		<comments>/wordpress/2009/08/iphone-note-6-tableview-as-single-selections/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 05:33:44 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=76</guid>
		<description><![CDATA[Today, I came up with a generic UITableViewController that allows single selections. Part 1: Creating the view controller.. 1. File -&#62; New File -&#62; UIViewController subclass. Check the checkbox UITableViewController subclass. CheckListTableViewController will be referred to as the controller from here on.. 2. The controller will accept: a. NSArray *array &#8211; which holds the items.]]></description>
			<content:encoded><![CDATA[<p>Today, I came up with a generic UITableViewController that allows single selections.</p>
<h3>Part 1: Creating the view controller..</h3>
<p>1. File -&gt; New File -&gt; UIViewController subclass. Check the checkbox UITableViewController subclass.</p>
<p>CheckListTableViewController will be referred to as the controller from here on..</p>
<p>2. The controller will accept:</p>
<p>a. NSArray *array &#8211; which holds the items.<br />
b. NSString *title &#8211; title of the selection.</p>
<p><span id="more-364"></span></p>
<p>3. I also added a protocol declaration for the controller when the user presses &#8220;Done&#8221; on the right portion of the Navbar.</p>
<p><em>CheckListTableViewController.h</em></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> CheckListTableViewControllerDelegate;
&nbsp;
<span style="color: #a61390;">@interface</span> CheckListTableViewController <span style="color: #002200;">:</span> UITableViewController <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//NSString *title;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>chosenString;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>array;
	<span style="color: #a61390;">id</span> delegate;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//@property(nonatomic, copy) NSString *title;</span>
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>array;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span> delegate;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithStyle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableViewStyle<span style="color: #002200;">&#41;</span>style withTitle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>t withArray<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>a;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>doneButtonPressed;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>initButton;
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> CheckListTableViewControllerDelegate
&nbsp;
@optional
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>checkListTableViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CheckListTableViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller didChooseString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>chosenString;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>4. In the cellForRowAtIndexPath, we display the checkmark if the cell&#8217;s current String is the same as the chosen String. The chosenString is an ivar which gets assigned during didSelectRowAtIndexPath. Notice that the assignment is performed AFTER the condition of comparing the strings.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Set up the cell...</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>currentString <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>array objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
	cell.textLabel.text <span style="color: #002200;">=</span> currentString;
	cell.textLabel.adjustsFontSizeToFitWidth <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>currentString localizedCaseInsensitiveCompare<span style="color: #002200;">:</span>chosenString<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedSame <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>cell setAccessoryType<span style="color: #002200;">:</span>UITableViewCellAccessoryCheckmark<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span><span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>cell setAccessoryType<span style="color: #002200;">:</span>UITableViewCellAccessoryNone<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Navigation logic may go here. Create and push another view controller.</span>
	<span style="color: #11740a; font-style: italic;">// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@&quot;AnotherView&quot; bundle:nil];</span>
	<span style="color: #11740a; font-style: italic;">// [self.navigationController pushViewController:anotherViewController];</span>
	<span style="color: #11740a; font-style: italic;">// [anotherViewController release];</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;User seleced row %d&quot;</span>, indexPath.row<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>currentString <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>array objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>currentString localizedCaseInsensitiveCompare<span style="color: #002200;">:</span>chosenString<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedSame <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span>indexPath<span style="color: #002200;">&#93;</span> setAccessoryType<span style="color: #002200;">:</span>UITableViewCellAccessoryCheckmark<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span><span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span>indexPath<span style="color: #002200;">&#93;</span> setAccessoryType<span style="color: #002200;">:</span>UITableViewCellAccessoryNone<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	chosenString <span style="color: #002200;">=</span> currentString;
&nbsp;
	<span style="color: #002200;">&#91;</span>tableView reloadData<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Part 2: Calling the controller from a client.</p>
<p>1. Make the client conform to the CheckListTableViewControllerDelegate.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
....
<span style="color: #6e371a;">#import &quot;DatePickerViewController.h&quot;</span>
<span style="color: #6e371a;">#import &quot;CheckListTableViewController.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> JobProfileViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span></pre></div></div>

<p>2. You can even reuse the controller for different lists, say we have two lists:&#8221;Purpose&#8221; and &#8220;Location&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>showPurposePicker<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;purpose button clicked&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>array <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Design&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Testing&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Purpose&quot;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self displayModalPickerForTitle<span style="color: #002200;">:</span>title withArray<span style="color: #002200;">:</span>array<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>showLocationOfWorkplace<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>array <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Both&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Private&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Public&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Location&quot;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self displayModalPickerForTitle<span style="color: #002200;">:</span>title withArray<span style="color: #002200;">:</span>array<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>3. The controller is added to a Navigation Controller which is presented modally. Courtesy of the help of Erica Sadun from IRC.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>displayModalPickerForTitle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>title withArray<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>array<span style="color: #002200;">&#123;</span>
&nbsp;
	CheckListTableViewController <span style="color: #002200;">*</span>listController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CheckListTableViewController alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewStylePlain withTitle<span style="color: #002200;">:</span>title withArray<span style="color: #002200;">:</span>array<span style="color: #002200;">&#93;</span>;
	listController.delegate <span style="color: #002200;">=</span> self;
&nbsp;
	UINavigationController <span style="color: #002200;">*</span>nav <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationController alloc<span style="color: #002200;">&#93;</span> initWithRootViewController<span style="color: #002200;">:</span>listController<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>nav animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>listController release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>nav release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>4. When the user is finished with the control, the client performs its necessary processes and dismisses the modal view.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>checkListTableViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CheckListTableViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller didChooseString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>chosenString<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Chosen String: %@&quot;</span>, chosenString<span style="color: #002200;">&#41;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Title: %@&quot;</span>, controller.title<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> controller.title <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Purpose&quot;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		job.purpose <span style="color: #002200;">=</span> chosenString;
		<span style="color: #002200;">&#91;</span>purpose setTitle<span style="color: #002200;">:</span>job.purpose forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> controller.title <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Principal Excavation Activity&quot;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		job.principalExcavationActivity <span style="color: #002200;">=</span> chosenString;
		<span style="color: #002200;">&#91;</span>principalExcavationActivity setTitle<span style="color: #002200;">:</span>job.principalExcavationActivity forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> controller.title <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Location Of Workplace&quot;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		job.locationOfWorkplace <span style="color: #002200;">=</span> chosenString;
		<span style="color: #002200;">&#91;</span>locationOfWorkplace setTitle<span style="color: #002200;">:</span>job.locationOfWorkplace forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>self dismissModalViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-6-tableview-as-single-selections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #6: Presenting a DatePicker as a ViewController Modally</title>
		<link>/wordpress/2009/08/iphone-note-5-presenting-a-datepicker-as-a-viewcontroller-modally/</link>
		<comments>/wordpress/2009/08/iphone-note-5-presenting-a-datepicker-as-a-viewcontroller-modally/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 02:38:23 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=72</guid>
		<description><![CDATA[Part 1: Creating your own control inside a view controller.. 1. File -&#62; New. Choose UIViewController subclass. Tick the checkbox &#8220;With XIB for user interface&#8221;. Save it as &#8220;DatePickerViewController&#8221;. 2. Open the DatePickerViewController.xib from IB. 3. In IB, drag a UIDatePicker and a UIButton as shown below. 4. In DatePickerViewController.h, #import &#160; @protocol DatePickerViewControllerDelegate; &#160;]]></description>
			<content:encoded><![CDATA[<h3>Part 1: Creating your own control inside a view controller..</h3>
<p>1. File -&gt; New. Choose UIViewController subclass. Tick the checkbox &#8220;With XIB for user interface&#8221;. Save it as &#8220;DatePickerViewController&#8221;.</p>
<p>2. Open the DatePickerViewController.xib from IB.</p>
<p>3. In IB, drag a UIDatePicker and a UIButton as shown below.</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/note-5-1.gif" alt="note-5-1.gif" border="0" width="150" height="235" /></p>
<p><span id="more-363"></span></p>
<p>4. In DatePickerViewController.h,</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> DatePickerViewControllerDelegate;
&nbsp;
<span style="color: #a61390;">@interface</span> DatePickerViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet UIDatePicker <span style="color: #002200;">*</span>datePicker;
	<span style="color: #a61390;">id</span> delegate;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>retain<span style="color: #002200;">&#41;</span> IBOutlet UIDatePicker <span style="color: #002200;">*</span>datePicker;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span> delegate;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithNibName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibNameOrNil bundle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSBundle</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibBundleOrNil;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>doneButtonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> DatePickerViewControllerDelegate
&nbsp;
@optional
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>datePickerViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>DatePickerViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller didChooseDate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>chosenDate;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>5. Now, lets hook up the &#8220;doneButtonPressed&#8221; in IB. In IB -&gt; Tools -&gt; Connections Inspector. Drag the touch &#8220;Touch Up Inside&#8221; event to the File&#8217;s Owner which is DatePickerViewController. Choose the method &#8220;doneButtonPressed:&#8221; when it shows up.</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/note-5-2.gif" alt="note-5-2.gif" border="0" width="291" height="224" /></p>
<p>6. Next, implement the doneButtonPressed</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;DatePickerViewController.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> DatePickerViewController
&nbsp;
<span style="color: #a61390;">@synthesize</span> datePicker, delegate;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithNibName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibNameOrNil bundle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSBundle</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibBundleOrNil <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithNibName<span style="color: #002200;">:</span>nibNameOrNil bundle<span style="color: #002200;">:</span>nibBundleOrNil<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// Custom initialization</span>
		self.title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Date Picker&quot;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//-(void)datePickerViewController:(DatePickerViewController *)controller didChooseDate:(NSString *)chosenDate;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>doneButtonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self.delegate respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>datePickerViewController<span style="color: #002200;">:</span>didChooseDate<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>dateFormatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>  autorelease<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>dateFormatter setDateStyle<span style="color: #002200;">:</span>NSDateFormatterMediumStyle<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>dateString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dateFormatter stringFromDate<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>datePicker date<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #002200;">&#91;</span>self.delegate datePickerViewController<span style="color: #002200;">:</span>self didChooseDate<span style="color: #002200;">:</span>dateString<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>datePicker release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<h3>Part 2: Displaying the view controller modally</h3>
<p>7. From this point on, I will refer to JobProfileViewController as the <em>client</em>. The client will create and present the DatePickerViewController modally (which is now referred to as <em>picker</em>). Once the user is finished using the picker and hits the &#8220;Done&#8221; button, the client will dismiss the picker and process the returned results.</p>
<p>8. Make the client conform to the DatePickerViewControllerDelegate.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;DatePickerViewController.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> JobProfileViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span></pre></div></div>

<p>9. Trigger an event to create and present the picker modally. In my case, its a button which is hooked up to showDatePicker method. Now, make the client as the delegate for the picker. Present the content modally then release the object.</p>
<p><em>JobProfileViewController.h:</em></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>showDatePicker<span style="color: #002200;">&#123;</span>
	DatePickerViewController <span style="color: #002200;">*</span>datePickerViewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>DatePickerViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;DatePickerViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	datePickerViewController.delegate <span style="color: #002200;">=</span> self;
&nbsp;
	<span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>datePickerViewController animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>datePickerViewController release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>10. Since the client is now the delegate for the picker, we can implement &#8220;didChooseDate&#8221; method inside the client. It is good practice that whoever (in our case the client) presents the content modally <em>should</em> also dismiss the content. Process what needs to be done, then let&#8217;s dismiss the modal content. <strong>Note: There is only one modal content for every view controller.</strong></p>
<p><em>JobProfileViewController.h:</em></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>datePickerViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>DatePickerViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller didChooseDate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>chosenDate<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Chosen Date as String: %@&quot;</span>, chosenDate <span style="color: #002200;">&#41;</span>;
&nbsp;
	job.startDate <span style="color: #002200;">=</span> chosenDate;
	<span style="color: #002200;">&#91;</span>startDate setTitle<span style="color: #002200;">:</span> chosenDate forState<span style="color: #002200;">:</span> UIControlStateNormal<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self dismissModalViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>UPDATE OCT 2, 2009: Download <a href="/wordpress/wp-content/uploads/2009/10/DatePickerModalExample.zip" title="DatePickerModalExample.zip">DatePickerModalExample.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-5-presenting-a-datepicker-as-a-viewcontroller-modally/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iPhone Note #5: SQLite3</title>
		<link>/wordpress/2009/08/iphone-note-sqlite3-tutorial/</link>
		<comments>/wordpress/2009/08/iphone-note-sqlite3-tutorial/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 09:44:13 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=64</guid>
		<description><![CDATA[Note this tutorial will be updated in the near future&#8230; 1. The code below (based from the SQLiteBooks Example) will copy the database from your bundle to the &#8220;Documents&#8221; directory. You don&#8217;t have to do this every time your app launches, so there is a check at &#8220;success&#8221; below. To check this, in the iPhone]]></description>
			<content:encoded><![CDATA[<p>Note this tutorial will be updated in the near future&#8230;</p>
<p>1. The code below (based from the <a href="">SQLiteBooks Example</a>) will copy the database from your bundle to the &#8220;Documents&#8221; directory. You don&#8217;t have to do this every time your app launches, so there is a check at &#8220;success&#8221; below. To check this, in the iPhone Simulator navigate to the Documents directory:</p>
<p><span id="more-360"></span></p>
<p><strong>/Users/rupert/Library/Application\ Support/iPhone\ Simulator/User/Applications/unique_number_of_the_application/Documents/sample.db</strong></p>
<pre>
// Creates a writable copy of the bundled default database in the application Documents directory.
- (void)createEditableCopyOfDatabaseIfNeeded {
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;

	//Documents Database Path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:kDatabaseName];

	success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;

    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kDatabaseName];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&amp;error];
    if (!success) {
        NSLog(@"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-sqlite3-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
