<?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</title>
	<atom:link href="http:///wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>By Rupert</description>
	<lastBuildDate>Sun, 07 Feb 2010 05:39:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails Note #14: QuickStart Tutorial</title>
		<link>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/</link>
		<comments>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 05:39:31 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">/wordpress/?p=707</guid>
		<description><![CDATA[If you haven&#8217;t installed ruby, follow this post
Part 1: Installation and Configuration (Rails and Passenger)
1. Upgrade existing ruby gems

sudo gem list
sudo gem update --system

UPDATE: Took me 4 hours figuring this out. There was a problem when i run script/console that it will say the &#8220;gem&#8221; detected was 1.0.1 although the current gem version is 1.3.5 [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t installed ruby, follow this <a href="/wordpress/2008/11/getting-my-feet-wet-in-ruby-on-rails/">post</a></p>
<p><strong>Part 1: Installation and Configuration (Rails and Passenger)</strong></p>
<p>1. Upgrade existing ruby gems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span></pre></div></div>

<p>UPDATE: Took me 4 hours figuring this out. There was a problem when i run script/console that it will say the &#8220;gem&#8221; detected was 1.0.1 although the current gem version is 1.3.5 after gem update &#8211;system. Google didn&#8217;t helped out. But I was able to nail down the problem from this post:</p>
<p><a href="https://wincent.com/wiki/Upgrading_to_RubyGems_1.0.1_on_Mac_OS_X_10.5.1">https://wincent.com/wiki/Upgrading_to_RubyGems_1.0.1_on_Mac_OS_X_10.5.1</a><br />
In the post above, notice that rubygems 1.0.1 was installed in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin. I guess this gem was being referenced first before the actual /usr/local/bin/gem. So I deleted this directory /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr.</p>
<p>Possible sources of gem installations:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems
<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>Gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:<span style="color: #000000;">1.8</span> rupert$ gem <span style="color: #c20cb9; font-weight: bold;">env</span>
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2008</span>-08-08 patchlevel <span style="color: #000000;">286</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin9.5.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
  - INSTALLATION DIRECTORY: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
  - RUBY EXECUTABLE: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby
  - EXECUTABLE DIRECTORY: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-<span style="color: #000000;">9</span>
  - GEM PATHS:
     - <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
     - <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
  - GEM CONFIGURATION:
     - :update_sources =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
     - :verbose =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
     - :benchmark =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">false</span>
     - :backtrace =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">false</span>
     - :bulk_threshold =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">1000</span>
  - REMOTE SOURCES:
     - http:<span style="color: #000000; font-weight: bold;">//</span>gems.rubyforge.org<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>2. Install rails. Download from ruby-forge. Link?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> rails-2.3.3.gem
gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> mysql</pre></div></div>

<p>3. Install and configure passenger for Apache2</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> passenger
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.5<span style="color: #000000; font-weight: bold;">/</span>bin
passenger-install-apache2-module</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">469 LoadModule passenger_module /Users/rupert/.gem/ruby/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
470 PassengerRoot /Users/rupert/.gem/ruby/1.8/gems/passenger-2.2.5
471 PassengerRuby /usr/local/bin/ruby
472 
473 &lt;VirtualHost *:80&gt;
474   RailsBaseURI /rails/travelsiteph
475 &lt;/VirtualHost&gt;</pre></div></div>

<p>4. Create a sample rails project (&#8221;travelsiteph&#8221;) in your project directory (&#8221;/Users/rupert/projects/rails&#8221;).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails
$ rails travelisteph
      create  
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers
      create  app<span style="color: #000000; font-weight: bold;">/</span>models
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts
      create  config<span style="color: #000000; font-weight: bold;">/</span>environments
	.....
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span> travelsiteph
drwxr-xr-x  <span style="color: #000000;">15</span> rupert  admin    <span style="color: #000000;">510</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> .
drwxr-xr-x   <span style="color: #000000;">5</span> rupert  admin    <span style="color: #000000;">170</span> <span style="color: #000000;">30</span> Sep <span style="color: #000000;">16</span>:<span style="color: #000000;">31</span> ..
<span style="color: #660033;">-rw-r--r--</span>   <span style="color: #000000;">1</span> rupert  admin  <span style="color: #000000;">10011</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> README
<span style="color: #660033;">-rw-r--r--</span>   <span style="color: #000000;">1</span> rupert  admin    <span style="color: #000000;">307</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> Rakefile
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> app
drwxr-xr-x   <span style="color: #000000;">9</span> rupert  admin    <span style="color: #000000;">306</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> config
drwxr-xr-x   <span style="color: #000000;">4</span> rupert  admin    <span style="color: #000000;">136</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">18</span> db
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> doc
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> lib
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> log
drwxr-xr-x  <span style="color: #000000;">11</span> rupert  admin    <span style="color: #000000;">374</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> public
drwxr-xr-x  <span style="color: #000000;">11</span> rupert  admin    <span style="color: #000000;">374</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> script
drwxr-xr-x   <span style="color: #000000;">8</span> rupert  admin    <span style="color: #000000;">272</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">55</span> <span style="color: #7a0874; font-weight: bold;">test</span>
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">22</span>:07 tmp
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> vendor</pre></div></div>

<p>I have /wwwroot as my document WebRoot. Its running cf, php and mapserv (cgi-bin). Since I want to mix it with rails development, I&#8217;ll just make a rails subdirectory. Inside the rails subdirectory, I can create symbolic links to my rails applications located in my projects directory. This way, rails configuration is not exposed from Apache.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> rails
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #000000; font-weight: bold;">/</span>public travelsiteph
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span>
total <span style="color: #000000;">8</span>
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin   <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:09 .
drwxrwxr-x  <span style="color: #000000;">60</span> root    admin  <span style="color: #000000;">2040</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:08 ..
lrwxr-xr-x   <span style="color: #000000;">1</span> rupert  admin    <span style="color: #000000;">42</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:09 travelsiteph -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #000000; font-weight: bold;">/</span>public</pre></div></div>

<p>5. Restart Apache to take the new configuration</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>StartupItems<span style="color: #000000; font-weight: bold;">/</span>Apache2<span style="color: #000000; font-weight: bold;">/</span>Apache2 restart</pre></div></div>

<p>6. Open http://127.0.0.1/rails/travelsiteph/</p>
<p><em>But for development purposes, it is better to use http://127.0.0.1:3000/ to see immediately any changes in code.</em> </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/rails.png" alt="rails.png" border="0" width="150" height="108" /></p>
<p><strong>Part 2: Rails Development</strong><br />
MySQL Prerequisites:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">*.*</span> <span style="color: #993333; font-weight: bold;">TO</span> rupert@<span style="color: #ff0000;">'%'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'*************'</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;
$ mysql <span style="color: #66cc66;">-</span>u rupert <span style="color: #66cc66;">-</span>p</pre></div></div>

<p>1. Create three databases:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_development;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_test;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_deployment;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>2. Launch Textmate</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph
mate .</pre></div></div>

<p>3. Edit database.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">development:
  adapter: mysql
  database: travelsiteph_development
  username: root
  password: xxxxxxx
  host: localhost
&nbsp;
test:
  adapter: mysql
  database: travelsiteph_test
  username: root
  password: xxxxxxx
  host: localhost
&nbsp;
production:
  adapter: mysql
  database: travelsiteph_deployment
  username: root
  password: xxxxxxx
  host: localhost</pre></div></div>

<p>4. Generate a Poi model. <em>The model should be capitalized and singular.</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate model Poi
      exists  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>poi.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>poi_test.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>pois.yml
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20090902111538</span>_create_pois.rb</pre></div></div>

<p>5. Now let&#8217;s create the database table for Poi using migrations.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Poi <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:pois</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:poi_id</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:full_address</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:location</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:get_there</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:short_description</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:full_description</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:other_info</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:tel_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:fax_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:mobile_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:website</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:other_contact_details</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:longitude</span>, <span style="color:#ff3333; font-weight:bold;">:decimal</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:latitude</span>, <span style="color:#ff3333; font-weight:bold;">:decimal</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:created_at</span>, <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">timestamps</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    drop_table <span style="color:#ff3333; font-weight:bold;">:pois</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rake db:migrate
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #7a0874; font-weight: bold;">&#41;</span>
==  CreatePois: migrating =========================================
<span style="color: #660033;">--</span> create_table<span style="color: #7a0874; font-weight: bold;">&#40;</span>:point_of_interests, <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">id</span></span>=<span style="color: #000000; font-weight: bold;">&gt;</span>:poi_id<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.0353s
==  CreatePois: migrated <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0362s<span style="color: #7a0874; font-weight: bold;">&#41;</span> ================================</pre></div></div>

<p>6. Generate a Poi controller.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>generate controller Poi
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>poi
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>poi_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>poi_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>poi_helper.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>poi_helper_test.rb</pre></div></div>

<p>7. Add a <em>list</em> function to Poi Controller</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PoiController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> list
    <span style="color:#0066ff; font-weight:bold;">@pois</span> = Poi.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>8. Lets test. Open a browser and point to http://127.0.0.1:3000/travelsiteph/poi/list</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$ruby</span> script<span style="color: #000000; font-weight: bold;">/</span>server</pre></div></div>

<p>9. Now create the view <em>list.rhtml</em> in <em>views/poi/</em></p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@pois</span>.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
	&lt;p&gt;There are currently no pois in the system. &lt;/p&gt;
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
	&lt;p&gt;These are the pois in the system: &lt;/p&gt;
&nbsp;
	&lt;ul&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#0066ff; font-weight:bold;">@pois</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>poi<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
			&lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> poi.<span style="color:#9900CC;">name</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:action <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'show'</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> poi.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>&lt;/li&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
	&lt;/ul&gt;
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><strong>Part 3: Deploying</strong><br />
1. set RAILS_ENV to production</p>
<pre>export RAILS_ENV=production</pre>
<p>2. Make sure to populate the database in production mode, run rake db:migrate</p>
<p>3. Capistrano</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:port</span>, <span style="color:#006666;">2210</span>
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;halalan2010&quot;</span>
<span style="color:#008000; font-style:italic;">#set :repository,  &quot;svn+ssh://2rmobile.com/data/repos/web/rails/halalan2010/&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;http://2rmobile.com/repos/web/rails/halalan2010/&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_username</span>, <span style="color:#996600;">'rupert'</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'SVN pass:'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;2rmobile.com&quot;</span> <span style="color:#008000; font-style:italic;"># IP Your HTTP server, Apache/etc</span>
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;2rmobile.com&quot;</span> <span style="color:#008000; font-style:italic;"># This may be the same as your `Web` server</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;2rmobile.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#008000; font-style:italic;"># This is where Rails migrations will run</span>
<span style="color:#008000; font-style:italic;">#role :db,  &quot;your slave db-server here&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>,  <span style="color:#996600;">&quot;rupert&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:runner</span>, <span style="color:#996600;">&quot;rupert&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/opt/rails/#{application}&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># If you are using Passenger mod_rails uncomment this:</span>
<span style="color:#008000; font-style:italic;"># if you're still using the script/reapear helper you will need</span>
<span style="color:#008000; font-style:italic;"># these http://github.com/rails/irs_process_scripts</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;/etc/init.d/apache2 start&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;/etc/init.d/apache2 stop&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
     run <span style="color:#996600;">&quot;#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:production</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;export RAILS_ENV=production&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{deploy_to}/current &amp;&amp; RAILS_ENV=production rake db:seed&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:populate</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{deploy_to}/current &amp;&amp; RAILS_ENV=production rake db:populate&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Capistrano commands I normally use:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#on local
#cap deploy:setup
&nbsp;
#on remote and change owner and permissions of project
sudo chown -Rf rupert:root halalan2010
&nbsp;
#on local
#cap deploy
#cap db:seed
#cap db:populate</pre></div></div>

<p><strong>Part 4: Miscellaneous</strong></p>
<p><strong>1. Get a description or rake commands</strong></p>
<pre>rake -D db</pre>
<p><strong>2. How to populate the database in production mode?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">rupert:halalan2010 rupert$ export RAILS_ENV=production
rupert:halalan2010 rupert$ rake db:migrate
(in /Users/rupert/projects/rails/halalan2010)
==  CreateDatabase: migrating =================================================
-- create_table(:candidates)
   -&gt; 0.0036s
-- create_table(:voters)
   -&gt; 0.0031s
-- create_table(:votes)
   -&gt; 0.0027s
==  CreateDatabase: migrated (0.0100s) ========================================</pre></div></div>

<p><a href="http://blog.airbladesoftware.com/2009/4/10/avoid-typing-rails_env-all-the-time">http://blog.airbladesoftware.com/2009/4/10/avoid-typing-rails_env-all-the-time</a></p>
<p><strong>3. Uninstall specific gem version</strong></p>
<pre>
gem uninstall activesupport -v 2.2.2
</pre>
<p><strong>4 Add a source to gem</strong></p>
<pre>
rupert:rails rupert$ sudo gem sources -a http://gems.github.com
http://gems.github.com added to sources
</pre>
<p><strong>5. Adding a rails project in svn</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#create a remote dir</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.2rmobile.com<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>web<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>virginmobilechecker
&nbsp;
<span style="color: #666666; font-style: italic;">#checkout and copy all files</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails
<span style="color: #c20cb9; font-weight: bold;">mv</span> virginmobilechecker virginmobilechecker_old
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #ff0000;">&quot;svn+ssh://2rmobile.com/data/repos/web/rails/virginmobilechecker&quot;</span> virginmobilechecker
<span style="color: #c20cb9; font-weight: bold;">mv</span> virginmobilechecker_old<span style="color: #000000; font-weight: bold;">/*</span> virginmobilechecker<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> virginmobilechecker
<span style="color: #c20cb9; font-weight: bold;">svn</span> add <span style="color: #000000; font-weight: bold;">*</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#ignoring log files</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> revert log<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*.log&quot;</span> log
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> tmp
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> doc
&nbsp;
<span style="color: #666666; font-style: italic;">#commit the files</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;first commit&quot;</span> <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/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
 [...]]]></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; projection library.
- samples
3. Build [...]]]></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 need 1000 page views (not clicks) [...]]]></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 be initiated; otherwise, NO to disallow editing.&#8221; 
2. Show [...]]]></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>Subversion</title>
		<link>/wordpress/2009/11/subversion/</link>
		<comments>/wordpress/2009/11/subversion/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 22:22:01 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">/wordpress/?p=634</guid>
		<description><![CDATA[This post will contain a summary of information regarding subversion scattered from old posts.
Installation on Debian
1. Packages

#apt-get install subversion
#apt-get install libapache2-svn

2. Login as root then create the repository.

#cd /data
#svnadmin create /repos --fs-type fsfs

3. Set the permissions

#groupadd subversion
#addgroup rupert subversion
#addgroup www-data subversion
&#160;
#chown -Rf www-data:subversion /data/repos
#chmod -Rf 770 repos

It&#8217;s better to set the necessary users and groups [...]]]></description>
			<content:encoded><![CDATA[<p>This post will contain a summary of information regarding subversion scattered from old posts.</p>
<h3>Installation on Debian</h3>
<p>1. Packages</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#apt-get install subversion
#apt-get install libapache2-svn</pre></div></div>

<p>2. Login as root then create the repository.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#cd /data
#svnadmin create /repos --fs-type fsfs</pre></div></div>

<p>3. Set the permissions</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#groupadd subversion
#addgroup rupert subversion
#addgroup www-data subversion
&nbsp;
#chown -Rf www-data:subversion /data/repos
#chmod -Rf 770 repos</pre></div></div>

<p>It&#8217;s better to set the necessary users and groups that would use subversion now. Later on, if we need to checkout using svn+ssh and setup a passwordless svn, then we won&#8217;t get permission issues.</p>
<p>4. In /etc/apache2/sites-available/2rmobile, add this to the configuration.</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">        &lt;Location /repos&gt;
        DAV svn
        SVNPath /data/repos
        SVNAutoversioning on
        AuthType Basic
        AuthName &quot;SVN - Your Project&quot;
        AuthUserFile /data/svn-auth-file
        Require valid-user
        &lt;/Location&gt;</pre></div></div>

<p>5. Enable the webdav module then restart apache.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#a2enmod dav
#a2enmod dav_svn
#/etc/init.d/apache2 restart</pre></div></div>

<h3>Passwordless SVN</h3>
<p>On your local macbook pro (mbp), we need to generate the ssh keys from the local machine, upload it to the remote machine and append it in the authorized_keys.</p>
<p><em>On the local machine:</em></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#ssh-keygen -t rsa
...
#cd /Users/rupert/.ssh
#scp -r id_rsa.pub rupert@2rmobile.com:/home/rupert/.ssh/id_rsa_mbp.pub</pre></div></div>

<p><em>On the remote machine:</em></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#cd ~/.ssh
#touch authorized_keys
#cat id_rsa_mbp.pub &gt;&gt; authorized_keys</pre></div></div>

<p>Test on the local machine by doing</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">ssh rupert@2rmobile.com</pre></div></div>

<p>. In my mbp, a dialog box from keychain is asking for the password. To circumvent this, we can add the passphrase to our identities.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#ssh-add -K
... enter the passphrase twice...
#ssh-add -k (adds it to the identities)
#ssh-add -l (lists the identities)</pre></div></div>

<p>Now the benefits of having a passwordless svn:<br />
- ofcourse it saves us a lot of time<br />
- rails capistrano deployment</p>
<p>References:<br />
<a href="http://www.howtoforge.com/debian_subversion_websvn">http://www.howtoforge.com/debian_subversion_websvn</a></p>
<h3>Subversion Tips and Tricks</h3>
<p><a href="http://subversion.tigris.org/faq.html#ssh-authorized-keys-trick">http://subversion.tigris.org/faq.html#ssh-authorized-keys-trick</a></p>
<p><strong>1. Checking out using svn+ssh and having passwordless ssh authentication. My personal favorite when working with personal projects since I have full control. </strong></p>
<pre>
svn co svn+ssh://www.2rmobile.com/data/repos/web/rails/halalan2010 halalan2010
</pre>
<p>But for work projects, I normally use webdav</p>
<pre>
svn co "http://www.2rmobile.com/repos/web/halalan2010" halalan2010
</pre>
<p><strong>2. svn+ssh on a custom or different port other than 22. I have my ssh on 2210, so we need to tell svn+ssh to use 2210</strong></p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">vim ~/.subversion/config
 41 [tunnels]
 42 ### Configure svn protocol tunnel schemes here.  By default, only
....
 53 ### built-in ssh scheme were not predefined, it could be defined
 54 ### as:
 55 ssh = $SVN_SSH ssh -p 2210</pre></div></div>

<p><a href="http://www.techper.net/2009/01/11/changing-port-number-of-svnssh-subversion-protocol/">http://www.techper.net/2009/01/11/changing-port-number-of-svnssh-subversion-protocol/</a></p>
<p><strong>3. svn diff</strong> &#8211; shows you the changes in a directory. This is useful for creating patches.</p>
<pre>
svn diff -r HEAD
svn st -q
</pre>
<p><strong>3. svn switch oldURL to newURL </strong>- very useful when I&#8217;m working at home or in the office, since the svn server has a public/private IP.</p>
<p><strong>4. svn log</strong> &#8211; shows you who committed and why (from the messages)</p>
<p><strong>5. ignoring specific files in a directory. i.e rails directories</strong></p>
<pre>svn propset svn:ignore "*.log" log</pre>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/11/subversion/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 with a gray [...]]]></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>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>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>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>3</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 [...]]]></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 [...]]]></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 code.
2. [...]]]></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;;
&#91;buttonLeft setTitle:@&#34;Left&#34; forState:UIControlStateNormal&#93;;
&#91;buttonLeft setFrame: [...]]]></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 meters. Let&#8217;s [...]]]></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 &#8220;enabled&#8221; switch is on or off?

NSUserDefaults *defaults = [...]]]></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>Mac Softwares and CheatSheet</title>
		<link>/wordpress/2009/08/mac-softwares-and-cheatsheet/</link>
		<comments>/wordpress/2009/08/mac-softwares-and-cheatsheet/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 11:36:15 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">/wordpress/?p=490</guid>
		<description><![CDATA[1. iTerm &#8211; terminal with tabs. 
2. MarsEdit- Blog Software. Im doing a local post on a local wordpress then copying and pasting to a remote wordpress.
3. Mac Shortcuts from http://www.danrodney.com/mac/index.html. Here&#8217;s a local post and another one.
4. How to create an ISO?
hdiutil makehybrid -o CS3v1.iso CS3
5. chmOX &#8211; CHM Viewer in OSX.
6. Git for [...]]]></description>
			<content:encoded><![CDATA[<p>1. <a href="http://iterm.sourceforge.net/download.shtml">iTerm</a> &#8211; terminal with tabs. </p>
<p>2. <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>- Blog Software. Im doing a local post on a local wordpress then copying and pasting to a remote wordpress.</p>
<p>3. Mac Shortcuts from <a href="http://www.danrodney.com/mac/index.html">http://www.danrodney.com/mac/index.html</a>. Here&#8217;s a <a href="/wordpress/2008/08/mac-shortcuts/">local post</a> and another <a href="/wordpress/2008/11/mac-tip-of-the-day-know-your-shortcuts/">one.</a></p>
<p>4. How to create an ISO?</p>
<pre>hdiutil makehybrid -o CS3v1.iso CS3</pre>
<p>5. <a href="http://chmox.sourceforge.net">chmOX</a> &#8211; CHM Viewer in OSX.</p>
<p>6. <a href="http://code.google.com/p/git-osx-installer/">Git</a> for OS X from google code.</p>
<p>7. Open a finder from terminal</p>
<pre>open .</pre>
<p>8. Keychain Access asking on passwordless ssh?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-add</span>
Enter passphrase: <span style="color: #000000; font-weight: bold;">******</span>
<span style="color: #c20cb9; font-weight: bold;">ssh-add</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">&lt;</span>To list your identities<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/mac-softwares-and-cheatsheet/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 instructions
4. In IB, [...]]]></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 protocols and [...]]]></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 [...]]]></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.
b. NSString *title &#8211; title of [...]]]></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;
@interface DatePickerViewController : UIViewController &#123;
	IBOutlet UIDatePicker *datePicker;
	id delegate;
&#125;
&#160;
@property &#40;retain&#41; [...]]]></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>2</slash:comments>
		</item>
	</channel>
</rss>
