<?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>cocoa*life</title>
	<atom:link href="http://www.cocoalife.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cocoalife.net</link>
	<description>Whether we can achieve something entirely depends upon our intensity of faith.</description>
	<lastBuildDate>Thu, 29 Jul 2010 15:22:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FreeBSD 8.1にavahiをインストールした</title>
		<link>http://www.cocoalife.net/2010/07/post_544.html</link>
		<comments>http://www.cocoalife.net/2010/07/post_544.html#comments</comments>
		<pubDate>Thu, 29 Jul 2010 15:22:52 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[UN*X]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=544</guid>
		<description><![CDATA[				FreeBSDでBonjour (Zero Configuration Networking)を使用したかったのですが、インストールしようとするといろいろと無駄なものが入るので、なるべく削った状態でインストールしたいというのが積年の思いでした。
				avahi 0.6.25まではどうしてもコンパイルがうまくいかなかったのですが、0.6.27になって（もしかしたら0.6.26でもいいのかも？）無事インストールができました。
				$ wget http://avahi.org/download/avahi-0.6.27.tar.gz
$ tar zxf avahi-0.6.27.tar.gz
$ cd avahi-0.6.27
$ ./configure --disable-glib --disable-gobject --disable-qt3 --disable-qt4 --disable-gtk --disable-dbus --disable-python --disable-mono --disable-autoipd --disable-gdbm --disable-gtk3 --disable-monodoc
$ gmake
$ sudo gmake install
				gmakeを使わないと
				sed -e 's,@sbindir\@,/usr/local/sbin,g'  > avahi-daemon.sh
というところで止まってしまいます。
あと行うべきことは2点。

/etc/rc.conf に avahi_daemon_enable=&#8221;YES&#8221; を記述する。
user/group に avahi を追加する。そうしないと
Failed to find user 'avahi'.
				と怒られて起動ができません。
				
				参考文献
				NetBSD on KuroBox : Instal the avahi
]]></description>
			<content:encoded><![CDATA[				<p>FreeBSDでBonjour (Zero Configuration Networking)を使用したかったのですが、インストールしようとするといろいろと無駄なものが入るので、なるべく削った状態でインストールしたいというのが積年の思いでした。</p>
				<p>avahi 0.6.25まではどうしてもコンパイルがうまくいかなかったのですが、0.6.27になって（もしかしたら0.6.26でもいいのかも？）無事インストールができました。</p>
				<pre>$ wget http://avahi.org/download/avahi-0.6.27.tar.gz
$ tar zxf avahi-0.6.27.tar.gz
$ cd avahi-0.6.27
$ ./configure --disable-glib --disable-gobject --disable-qt3 --disable-qt4 --disable-gtk --disable-dbus --disable-python --disable-mono --disable-autoipd --disable-gdbm --disable-gtk3 --disable-monodoc
$ gmake
$ sudo gmake install</pre>
				<p>gmakeを使わないと</p>
				<pre>sed -e 's,@sbindir\@,/usr/local/sbin,g'  > avahi-daemon.sh</pre>
<p>というところで止まってしまいます。</p>
<p>あと行うべきことは2点。</p>
<ul>
<li>/etc/rc.conf に avahi_daemon_enable=&#8221;YES&#8221; を記述する。</li>
<li>user/group に avahi を追加する。そうしないと
<pre>Failed to find user 'avahi'.</pre>
				<p>と怒られて起動ができません。</li>
				</ul>
				<h2>参考文献</h2>
				<p><a target="_blank" href="http://homepage3.nifty.com/extant/misc/NetBSD_on_KuroBox_Avahi.html">NetBSD on KuroBox : Instal the avahi</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/07/post_544.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZFS（raidz2 + spare）での修復の実際</title>
		<link>http://www.cocoalife.net/2010/07/post_823.html</link>
		<comments>http://www.cocoalife.net/2010/07/post_823.html#comments</comments>
		<pubDate>Fri, 02 Jul 2010 22:54:55 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[UN*X]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=823</guid>
		<description><![CDATA[				家で使用している、ファイルサーバはFreeBSD 8.0とZFSを使用して構築したものです。
				先日、接続すると上手く反応してくれなくなっていたので、調べてみたら一つのディスクがエラーを出している様子。
				環境は以下のようになります。
				da0: Seagate ST3500410AS
				da1 &#8211; da7: HGST HDP725050GLA360
				新しいHDD: HGST HDS721010CLA332
				ログは確かこんな感じ（消してしまったので適当に細工）。
				# zpool status
  pool: pool state: DEGRADED
status: One or more devices has experienced an unrecoverable error.  An
        attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and [...]]]></description>
			<content:encoded><![CDATA[				<p>家で使用している、ファイルサーバはFreeBSD 8.0とZFSを使用して構築したものです。<br />
				先日、接続すると上手く反応してくれなくなっていたので、調べてみたら一つのディスクがエラーを出している様子。</p>
				<p>環境は以下のようになります。<br />
				da0: Seagate ST3500410AS<br />
				da1 &#8211; da7: HGST HDP725050GLA360<br />
				新しいHDD: HGST HDS721010CLA332</p>
				<p>ログは確かこんな感じ（消してしまったので適当に細工）。</p>
				<pre># zpool status
  pool: pool state: DEGRADED
status: One or more devices has experienced an unrecoverable error.  An
        attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
        using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://www.sun.com/msg/ZFS-8000-9P
 scrub:  none requested
config:

        NAME        STATE     READ WRITE CKSUM
        pool        DEGRADED     0     0     0
          raidz2    DEGRADED     0     0     0
            da1     ONLINE       0     0     0  81.1M resilvered
            da2     ONLINE       0     0     0  81.1M resilvered
            da3     DEGRADED   209  449K     0
            da4     ONLINE       0     0     0  81.1M resilvered
            da5     ONLINE       0     0     0  81.1M resilvered
            da6     ONLINE       0     0     0  81.1M resilvered
            da7     ONLINE       0     0     0  81.1M resilvered
        spares
          da0       AVAIL</pre>
				<p>da3の調子が悪いみたいです。<br />
				こんなときにと用意していた、ホットスペアは勝手に使用してくれない様なので、手動でreplaceします。</p>
				<pre># zpool replace da3 da0
# zpool status
  pool: pool state: DEGRADED
status: One or more devices has experienced an unrecoverable error.  An
        attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
        using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://www.sun.com/msg/ZFS-8000-9P
 scrub: resilver completed after 2h14m with 0 errors on Thu Jul  1 03:24:59 2010
config:

        NAME        STATE     READ WRITE CKSUM
        pool        DEGRADED     0     0     0
          raidz2    DEGRADED     0     0     0
            da1     ONLINE       0     0     0  81.1M resilvered
            da2     ONLINE       0     0     0  81.1M resilvered
            spare   DEGRADED     0     0     0
              da3   OFFLINE    209  449K     0
              da0   ONLINE       0     0     0  152G resilvered
            da4     ONLINE       0     0     0  81.1M resilvered
            da5     ONLINE       0     0     0  81.1M resilvered
            da6     ONLINE       0     0     0  81.1M resilvered
            da7     ONLINE       0     0     0  81.1M resilvered
        spares
          da0       INUSE     currently in use</pre>
				<p>このままだとずっとdegradedという嫌な表示が出たままなのでda3を切り離します。</p>
				<pre># zpool detach pool da3</pre>
<p>いったんマシンの電源を落とし、新しいHDDを入れて起動すると</p>
<pre># zpool status
NAME        STATE     READ WRITE CKSUM
pool        UNAVAIL      0     0     0  insufficient replicas
  raidz2    UNAVAIL      0     0     0  insufficient replicas
    da1     ONLINE       0     0     0
    da2     ONLINE       0     0     0
    da0     ONLINE       0     0     0
    da4     FAULTED      0     0     0  corrupted data
    da5     FAULTED      0     0     0  corrupted data
    da6     FAULTED      0     0     0  corrupted data
    da7     UNAVAIL      0     0     0  corrupted data</pre>
				<p>となってしまい、使用できない状態。<br />
				どうなっているのかを調べてみると、da3 => da7になり、da4以降が一つずつ前にずれている状態。<br />
				先でda3はdetachされているので、da4だったda3が見えていないと。</p>
				<p>HDDのScan Orderは変えられないし、どうしたものかと悩んで調べていたら、ただ単純にexportしてimportすれば良いだけということがわかりました。</p>
				<pre># zpool export pool
# zpool import pool</pre>
				<pre># zpool status
  pool: pool
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        pool        ONLINE       0     0     0
          raidz2    ONLINE       0     0     0
            da1     ONLINE       0     0     0
            da2     ONLINE       0     0     0
            da0     ONLINE       0     0     0
            da3     ONLINE       0     0     0
            da4     ONLINE       0     0     0
            da5     ONLINE       0     0     0
            da6     ONLINE       0     0     0
</pre>
				<p>めでたく戻ってる！<br />
				最後は、spareはspareに戻しました。</p>
				<pre># zpool replace pool da0 da7
# zpool status
  pool: pool
 state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
        continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
 scrub: resilver in progress for 0h47m, 40.25% done, 1h10m to go
config:

        NAME           STATE     READ WRITE CKSUM
        pool           ONLINE       0     0     0
          raidz2       ONLINE       0     0     0
            da1        ONLINE       0     0     0  31.1M resilvered
            da2        ONLINE       0     0     0  31.1M resilvered
            replacing  ONLINE       0     0     0
              da0      ONLINE       0     0     0
              da7      ONLINE       0     0     0  61.4G resilvered
            da3        ONLINE       0     0     0  31.0M resilvered
            da4        ONLINE       0     0     0  31.0M resilvered
            da5        ONLINE       0     0     0  31.0M resilvered
            da6        ONLINE       0     0     0  31.0M resilvered</pre>
				<pre># zpool add pool spare da0
# zpool status
  pool: pool
 state: ONLINE
 scrub: resilver completed after 2h21m with 0 errors on Sat Jul  3 07:07:19 2010
config:

        NAME        STATE     READ WRITE CKSUM
        pool        ONLINE       0     0     0
          raidz2    ONLINE       0     0     0
            da1     ONLINE       0     0     0  79.7M resilvered
            da2     ONLINE       0     0     0  79.6M resilvered
            da7     ONLINE       0     0     0  152G resilvered
            da3     ONLINE       0     0     0  79.6M resilvered
            da4     ONLINE       0     0     0  79.6M resilvered
            da5     ONLINE       0     0     0  79.6M resilvered
            da6     ONLINE       0     0     0  79.6M resilvered
        spares
          da0       AVAIL   

errors: No known data errors</pre>
				<p>らくちんらくちんです。</p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://wiki.livedoor.jp/zfslab/d/USB%A5%E1%A5%E2%A5%EA3%CB%DC%A4%C7raidz%A4%CE%BC%C2%B8%B3">USBメモリ3本でraidzの実験 &#8211; Solaris,ZFS研究室Wiki &#8211; livedoor Wiki（ウィキ）</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/07/post_823.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Data APIs Objective-C Client LibraryをiOS SDKで使用するための準備</title>
		<link>http://www.cocoalife.net/2010/06/post_547.html</link>
		<comments>http://www.cocoalife.net/2010/06/post_547.html#comments</comments>
		<pubDate>Fri, 18 Jun 2010 07:58:27 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=547</guid>
		<description><![CDATA[				以下の文章は、Google Data APIs Objective-C Client LibraryをiOS SDKで使用するための準備 &#124; アクトインディ技術部隊報告書と同じものです。
				今回はGoogle Data APIs Objective-C Client LibraryをiOS SDKで使用するための準備について書きたいと思います。
				Google Data APIs Objective-C Client LibraryはGoogleの様々なサービスをObjective-Cから使うことができるライブラリです。
				Google Data APIs Objective-C Client Library
				あらかじめGData.xcodeprojを、ライブラリを使用したいプロジェクトの「ファイルとグループ」欄に追加しておきましょう。
				ライブラリをコンパイルする
				コンパイルオプションを指定してコンパイルします。
				今回はPicasaサービスとそれに付随してOAuthを使用したので、以下のオプションを指定しました。
				-DGDATA_INCLUDE_PHOTOS_SERVICE=1
-DGDATA_INCLUDE_OAUTH=1
				iPhone Simulator版とiPhone OS版をReleaseでコンパイルします。
				lipoでFat Binaryにする
				cd build
lipo -create Release-iphoneos/libGDataTouchStaticLib.a Release-iphonesimulator/libGDataTouchStaticLib.a -output libGDataTouchStaticLib.a
				コンパイルしたライブラリをXcodeに追加する
				
				Xcodeの「ターゲット」でアプリを指定し右クリックし「情報を見る」を選択。
				「一般」 &#8211; 「リンク済みライブラリ」の下の「+」をクリック。
				「その他を追加&#8230;」をクリックし、さきほどコンパイルしたlibGDataTouchStaticLib.aを選択。
				
				コンパイルするための設定を追加する
				
				プロジェクトを右クリックし、「情報を見る」を選択。
				「ビルド」を選ぶ。
				「ヘッダ検索パス」に/usr/include/libxml2を追加。
				「ユーザヘッダ検索パス」にライブラリのフォルダを追加（このとき「再帰的」にチェックを入れる）。
				「常にユーザパスを検索」にチェックを入れる。
				「他のリンカフラグ」に -all_load -ObjC -lxml2 を指定。
				
				参考文献
				
				BuildingTheLibrary &#8211; gdata-objectivec-client &#8211; Adding the Google Data API Objective-C Client Library to a Project &#8211; [...]]]></description>
			<content:encoded><![CDATA[				<p>以下の文章は、<a href="http://tech.actindi.net/3485836586">Google Data APIs Objective-C Client LibraryをiOS SDKで使用するための準備 | アクトインディ技術部隊報告書</a>と同じものです。</p>
				<p>今回はGoogle Data APIs Objective-C Client LibraryをiOS SDKで使用するための準備について書きたいと思います。</p>
				<p>Google Data APIs Objective-C Client LibraryはGoogleの様々なサービスをObjective-Cから使うことができるライブラリです。<br />
				<a target="_blank" href="http://code.google.com/p/gdata-objectivec-client/">Google Data APIs Objective-C Client Library</a></p>
				<p>あらかじめGData.xcodeprojを、ライブラリを使用したいプロジェクトの「ファイルとグループ」欄に追加しておきましょう。</p>
				<h2>ライブラリをコンパイルする</h2>
				<p>コンパイルオプションを指定してコンパイルします。<br />
				今回はPicasaサービスとそれに付随してOAuthを使用したので、以下のオプションを指定しました。</p>
				<pre>-DGDATA_INCLUDE_PHOTOS_SERVICE=1
-DGDATA_INCLUDE_OAUTH=1</pre>
				<p>iPhone Simulator版とiPhone OS版をReleaseでコンパイルします。</p>
				<h2>lipoでFat Binaryにする</h2>
				<pre>cd build
lipo -create Release-iphoneos/libGDataTouchStaticLib.a Release-iphonesimulator/libGDataTouchStaticLib.a -output libGDataTouchStaticLib.a</pre>
				<h2>コンパイルしたライブラリをXcodeに追加する</h2>
				<ul>
				<li>Xcodeの「ターゲット」でアプリを指定し右クリックし「情報を見る」を選択。</li>
				<li>「一般」 &#8211; 「リンク済みライブラリ」の下の「+」をクリック。</li>
				<li>「その他を追加&#8230;」をクリックし、さきほどコンパイルしたlibGDataTouchStaticLib.aを選択。</li>
				</ul>
				<h2>コンパイルするための設定を追加する</h2>
				<ul>
				<li>プロジェクトを右クリックし、「情報を見る」を選択。</li>
				<li>「ビルド」を選ぶ。</li>
				<li>「ヘッダ検索パス」に/usr/include/libxml2を追加。</li>
				<li>「ユーザヘッダ検索パス」にライブラリのフォルダを追加（このとき「再帰的」にチェックを入れる）。</li>
				<li>「常にユーザパスを検索」にチェックを入れる。</li>
				<li>「他のリンカフラグ」に -all_load -ObjC -lxml2 を指定。</li>
				</ul>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://code.google.com/p/gdata-objectivec-client/wiki/BuildingTheLibrary#Linking_to_the_iPhone_Static_Library">BuildingTheLibrary &#8211; gdata-objectivec-client &#8211; Adding the Google Data API Objective-C Client Library to a Project &#8211; Project Hosting on Google Code</a></li>
				<li><a href="http://d.hatena.ne.jp/unarrator/20100602">gdata-objectivec-clientを一部手動でstatic library化 &#8211; Undecidable Narrator &#8211; 曖昧な語り手</a></li>
				<li><a href="http://www.awaresoft.jp/development/35-iphone-app/62-building-gdata-api-client-library-for-iphone.html">Google Data API クライアントライブラリのビルド &#8211; Awaresoft</a></li>
				<li><a target="_blank" href="http://blog.boreal-kiss.com/2009/08/29000009.html">[iPhone] cocos2dを静的ライブラリ化して使う : boreal-kiss.com</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/06/post_547.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>O&#8217;Reillyの電子書籍iPhoneアプリから.epubファイルを自作する</title>
		<link>http://www.cocoalife.net/2010/05/post_549.html</link>
		<comments>http://www.cocoalife.net/2010/05/post_549.html#comments</comments>
		<pubDate>Sun, 16 May 2010 05:04:31 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Book]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=549</guid>
		<description><![CDATA[				O&#8217;Reillyでは低価格で電子書籍のiPhoneアプリケーションを配布しています。
				
				このように600円とか700円とかのものが非常に多いです。
				こんな低価格でも十分太っ腹なのに、さらにすごいのは、アプリを解凍してあげれば中にEPUBフォーマットで作成されたフォルダがまんま入っていて、自由にMacからでも見ることが出来る点です。
				当のO&#8217;Reillyのサイトにもやり方が書いてあります。
				Ebook Bundles &#8211; Getting The Most
				
				iTunesで購入した本を選択し右クリックし、「Finder」を選択。
				そのアプリのファイル（〜.ipa）を探す（多分すでにフォーカスが当たっている）。
				そのアプリのファイルを別のところにコピーし、拡張子をzipにリネーム。
				zipを解凍し、中に入っているPayload/bookというフォルダがEPUBフォーマットになっている。
				さらにその中のOEBPSフォルダを開けばxhtmlがあるので、それを表示させればMacでも表示が出来る。
				
				せっかくEPUBフォーマットになっているのですから、ここはiPadのiBooksで表示させたい。
				ということで、.epubファイルを作成します。
				
				
				bookフォルダ以下のMETA-INF, mimetype, OEBPSの3つのフォルダを選択する。
				右クリックし「3項目を圧縮」を選択。
				出来たzipファイルの拡張子を.epubに変更する。
				
				あとはiTunesにドロップしてあげましょう。
				まだiPadを持っていないので、実際にiBooksに転送して見ることは出来ませんが、今から非常に楽しみです。
				P.S.
				Mac/iPhoneアプリもあるStanzaでも転送することが出来、表示することが出来ました。1
				参考文献
				
				Ebook Bundles &#8211; Getting The Most
				Convert cheap O’Reilly iPhone App Books to .epub « I am Zef
				
				もともとのO&#8217;ReillyのiPhoneアプリのバックエンドはStanzaですから当たり前といえば当たり前ですが・・・。
]]></description>
			<content:encoded><![CDATA[				<p>O&#8217;Reillyでは低価格で電子書籍のiPhoneアプリケーションを配布しています。</p>
				<p><a href="http://www.cocoalife.net/wp-content/uploads/2010/05/1601.png"><img class="alignnone" title="" src="http://www.cocoalife.net/wp-content/uploads/2010/05/1601.png" alt="" width="320" /></a></p>
				<p>このように600円とか700円とかのものが非常に多いです。<br />
				こんな低価格でも十分太っ腹なのに、さらにすごいのは、アプリを解凍してあげれば中にEPUBフォーマットで作成されたフォルダがまんま入っていて、自由にMacからでも見ることが出来る点です。</p>
				<p>当のO&#8217;Reillyのサイトにもやり方が書いてあります。<br />
				<a target="_blank" href="http://oreilly.com/ebooks/oreilly_iphone_tips.csp">Ebook Bundles &#8211; Getting The Most</a></p>
				<ol>
				<li>iTunesで購入した本を選択し右クリックし、「Finder」を選択。</li>
				<li>そのアプリのファイル（〜.ipa）を探す（多分すでにフォーカスが当たっている）。</li>
				<li>そのアプリのファイルを別のところにコピーし、拡張子をzipにリネーム。</li>
				<li>zipを解凍し、中に入っているPayload/bookというフォルダがEPUBフォーマットになっている。</li>
				<li>さらにその中のOEBPSフォルダを開けばxhtmlがあるので、それを表示させればMacでも表示が出来る。</li>
				</ol>
				<p>せっかくEPUBフォーマットになっているのですから、ここはiPadのiBooksで表示させたい。<br />
				ということで、.epubファイルを作成します。</p>
				<p><a href="http://www.cocoalife.net/wp-content/uploads/2010/05/1602.png"><img class="alignnone" title="" src="http://www.cocoalife.net/wp-content/uploads/2010/05/1602.png" alt="" /></a></p>
				<ol>
				<li>bookフォルダ以下のMETA-INF, mimetype, OEBPSの3つのフォルダを選択する。</li>
				<li>右クリックし「3項目を圧縮」を選択。</li>
				<li>出来たzipファイルの拡張子を.epubに変更する。</li>
				</ol>
				<p>あとはiTunesにドロップしてあげましょう。<br />
				まだiPadを持っていないので、実際にiBooksに転送して見ることは出来ませんが、今から非常に楽しみです。</p>
				<p>P.S.<br />
				Mac/iPhoneアプリもある<a target="_blank" href="http://www.lexcycle.com/">Stanza</a>でも転送することが出来、表示することが出来ました。<sup><a href="http://www.cocoalife.net/2010/05/post_549.html#footnote_0_549" id="identifier_0_549" class="footnote-link footnote-identifier-link" title="もともとのO&amp;#8217;ReillyのiPhoneアプリのバックエンドはStanzaですから当たり前といえば当たり前ですが・・・。">1</a></sup></p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://oreilly.com/ebooks/oreilly_iphone_tips.csp">Ebook Bundles &#8211; Getting The Most</a></li>
				<li><a target="_blank" href="http://zef.me/3246/convert-cheap-oreilly-iphone-app-books-to-epub">Convert cheap O’Reilly iPhone App Books to .epub « I am Zef</a></li>
				</ul>
				<ol class="footnotes"><li id="footnote_0_549" class="footnote">もともとのO&#8217;ReillyのiPhoneアプリのバックエンドはStanzaですから当たり前といえば当たり前ですが・・・。</li></ol>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/05/post_549.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Objective-Cでメンバ変数に動的にアクセスする方法</title>
		<link>http://www.cocoalife.net/2010/04/post_548.html</link>
		<comments>http://www.cocoalife.net/2010/04/post_548.html#comments</comments>
		<pubDate>Sun, 25 Apr 2010 01:24:58 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=548</guid>
		<description><![CDATA[				以下の文章はObjective-Cでメンバ変数に動的にアクセスする方法 &#124; アクトインディ技術部隊報告書と同様のものです。
				今回、複数回使い回したいViewがあったのですが、一方で様々なところで使われるものではありませんでした。
				こんなときにわざわざクラスを作るのはどうも重い感じがしてしまいます。
				そこでUIViewのサブクラスを作らずに、メソッドで作ることにしました。
				
				UIViewController
				
				今回作成したいView
				今回作成したいView
				
				
				というように複数個必要です。
				このViewの中身はUILabelが2つだけ。
				さらに出来ることなら、作成するViewの中身であるUILabelを、このViewを持っているViewControllerのメンバ変数からアクセスしたい。
				以前はTagを割り当ててアクセスしていたのですが、意外と面倒だったのでそれ以外の方法がないかどうか調べてみました。
				実際には以下のようなコードを使用することで出来ました。
				#include &#60;objc/runtime.h&#62;

@implementation HogeViewController

- (UIView *)generateView:(NSString *)titleLabelName contentLabelName:(NSString *)contentLabelName
{
    UIView   *resultView;
    UILabel  *titleLabel, *contentLabel;

    // 便宜上CGRectZeroを使います。
    resultView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

    titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [resultView addSubview:titleLabel];
    [titleLabel [...]]]></description>
			<content:encoded><![CDATA[				<p>以下の文章は<a target="_blank" href="http://tech.actindi.net/3481147128">Objective-Cでメンバ変数に動的にアクセスする方法 | アクトインディ技術部隊報告書</a>と同様のものです。</p>
				<p>今回、複数回使い回したいViewがあったのですが、一方で様々なところで使われるものではありませんでした。<br />
				こんなときにわざわざクラスを作るのはどうも重い感じがしてしまいます。<br />
				そこでUIViewのサブクラスを作らずに、メソッドで作ることにしました。</p>
				<ul>
				<li>UIViewController
				<ul>
				<li>今回作成したいView</li>
				<li>今回作成したいView</li>
				</ul>
				</ul>
				<p>というように複数個必要です。<br />
				このViewの中身はUILabelが2つだけ。</p>
				<p>さらに出来ることなら、作成するViewの中身であるUILabelを、このViewを持っているViewControllerのメンバ変数からアクセスしたい。<br />
				以前はTagを割り当ててアクセスしていたのですが、意外と面倒だったのでそれ以外の方法がないかどうか調べてみました。</p>
				<p>実際には以下のようなコードを使用することで出来ました。</p>
				<pre class="brush: objc;">#include &lt;objc/runtime.h&gt;

@implementation HogeViewController

- (UIView *)generateView:(NSString *)titleLabelName contentLabelName:(NSString *)contentLabelName
{
    UIView   *resultView;
    UILabel  *titleLabel, *contentLabel;

    // 便宜上CGRectZeroを使います。
    resultView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

    titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [resultView addSubview:titleLabel];
    [titleLabel release];

    object_setInstanceVariable(self, [titleLabelName UTF8String], titleLabel);

    contentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [resultView addSubview:contentLabel];
    [contentLabel release];

    object_setInstanceVariable(self, [contentLabelName UTF8String], contentLabel);

    return resultView;
}

@end</pre>
				<p>titleLabelName, contentLabelNameにはそれぞれに割り当てたいメンバ変数の名称を指定します。<br />
				こんな感じにobject_setInstanceVariable関数を使用してあげれば、割り当てたいメンバ変数に割り当てることが出来ます。</p>
				<p>P.S.<br />
				といいつつも、実は様々なところで使われる必要がわかり、まじめにUIViewのサブクラスを作成したため、上記のコードはお蔵入りになりました。</p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://journal.mycom.co.jp/column/objc/031/index.html">【コラム】ダイナミックObjective-C (31) ランタイムAPIでさらに動的に(5) &#8211; インスタンス変数に動的にアクセス | エンタープライズ | マイコミジャーナル</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/04/post_548.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UITableViewにcellを動的に追加/削除する2つの方法。</title>
		<link>http://www.cocoalife.net/2010/04/post_543.html</link>
		<comments>http://www.cocoalife.net/2010/04/post_543.html#comments</comments>
		<pubDate>Wed, 14 Apr 2010 03:57:48 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=543</guid>
		<description><![CDATA[				以下の文章はUITableViewにcellを動的に追加/削除する2つの方法。 &#124; アクトインディ技術部隊報告書と同様のものです。
				UITableViewにcellを動的に追加/削除するということについて書こうと思います。
				特にこれまでUITableViewのbeginUpdatesとendUpdatesという二つのメソッドを、いったいどんな場合に使用したらいいのか明確になっていませんでした。
				ここら辺を重点的に書きたいと思います。
				以下のAppleの公式ドキュメントにかなり詳しく書かれています。
				Table View Programming Guide for iPhone OS: Inserting and Deleting Rows and Sections
				cellを一つずつ追加/削除していく場合
				cellを一つずつ追加/削除していく場合には、beginUpdates/endUpdatesの出番はありません。
				追加/削除したいcellのindexPathを作成してinsert(or delete)RowsAtIndexPaths:withRowAnimation:メソッドを呼ぶだけ。
				単純です。
				ただし注意点はinsertRowsAtIndexPaths:withRowAnimation:メソッドを呼ぶと、UITableViewDataSourceのtableView:cellForRowAtIndexPath:メソッドが呼ばれるということ。
				すなわち、cellの中身をNSArray等で管理している場合にはあらかじめNSArrayの内容を変更しておかなければなりません。
				cocoa*life &#8211; UITableViewCellを削除ボタンを使って削除する
				複数のcellをいっぺんに追加/削除する場合
				ここまではbeginUpdatesやendUpdatesを使用する必要はありません。
				では、どういうときに使用するべきなのか？
				ポイントはbeginUpdates/endUpdatesに関することが書かれているセクションのタイトルがBatch Insertion and Deletion of Rows and Sectionsであるということ。
				batchというのは英語で束という意味なので、「いっぺん」に複数のcellを処理したいときに使うということになります。
				つまり、このメソッドを使用するかしないかの選択基準の違いは、一つずつかいっぺんかということになります。
				もちろん複数のcellを追加/削除したい場合であっても、一つずつ追加/削除することができます。
				beginUpdatesとendUpdatesで追加/削除のメソッド群を挟みます。
				endUpdatesを呼び出したあと、tableView:cellForRowAtIndexPath:メソッドが呼ばれ、追加と削除の結果が表示されます。
				beginUpdatesとendUpdatesで挟まれた追加/削除の挙動は、公式ドキュメントに以下のように書かれています。
				
				
				
				The code calls the deleteRowsAtIndexPaths:withRowAnimation: method after it calls insertRowsAtIndexPaths:withRowAnimation:. However, this is not the order in which UITableView completes the operations. It defers any insertions of rows or sections until [...]]]></description>
			<content:encoded><![CDATA[				<p>以下の文章は<a target="_blank" href="http://tech.actindi.net/3480206140">UITableViewにcellを動的に追加/削除する2つの方法。 | アクトインディ技術部隊報告書</a>と同様のものです。</p>
				<p>UITableViewにcellを動的に追加/削除するということについて書こうと思います。</p>
				<p>特にこれまでUITableViewのbeginUpdatesとendUpdatesという二つのメソッドを、いったいどんな場合に使用したらいいのか明確になっていませんでした。<br />
				ここら辺を重点的に書きたいと思います。</p>
				<p>以下のAppleの公式ドキュメントにかなり詳しく書かれています。<br />
				<a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html">Table View Programming Guide for iPhone OS: Inserting and Deleting Rows and Sections</a></p>
				<h2>cellを一つずつ追加/削除していく場合</h2>
				<p>cellを一つずつ追加/削除していく場合には、beginUpdates/endUpdatesの出番はありません。<br />
				追加/削除したいcellのindexPathを作成してinsert(or delete)RowsAtIndexPaths:withRowAnimation:メソッドを呼ぶだけ。<br />
				単純です。</p>
				<p>ただし注意点はinsertRowsAtIndexPaths:withRowAnimation:メソッドを呼ぶと、UITableViewDataSourceのtableView:cellForRowAtIndexPath:メソッドが呼ばれるということ。<br />
				すなわち、cellの中身をNSArray等で管理している場合にはあらかじめNSArrayの内容を変更しておかなければなりません。</p>
				<p><a target="_blank" href="http://www.cocoalife.net/2008/12/post_767.html">cocoa*life &#8211; UITableViewCellを削除ボタンを使って削除する</a></p>
				<h2>複数のcellをいっぺんに追加/削除する場合</h2>
				<p>ここまではbeginUpdatesやendUpdatesを使用する必要はありません。<br />
				では、どういうときに使用するべきなのか？</p>
				<p>ポイントはbeginUpdates/endUpdatesに関することが書かれているセクションのタイトルがBatch Insertion and Deletion of Rows and Sectionsであるということ。<br />
				batchというのは英語で束という意味なので、「いっぺん」に複数のcellを処理したいときに使うということになります。</p>
				<p>つまり、このメソッドを使用するかしないかの選択基準の違いは、一つずつかいっぺんかということになります。<br />
				もちろん複数のcellを追加/削除したい場合であっても、一つずつ追加/削除することができます。</p>
				<p>beginUpdatesとendUpdatesで追加/削除のメソッド群を挟みます。<br />
				endUpdatesを呼び出したあと、tableView:cellForRowAtIndexPath:メソッドが呼ばれ、追加と削除の結果が表示されます。</p>
				<p>beginUpdatesとendUpdatesで挟まれた追加/削除の挙動は、公式ドキュメントに以下のように書かれています。</p>
				<dl class="quote">
				<dd>
				<blockquote>
				<p>The code calls the deleteRowsAtIndexPaths:withRowAnimation: method <strong>after</strong> it calls insertRowsAtIndexPaths:withRowAnimation:. However, this is <strong>not the order</strong> in which UITableView completes the operations. It defers <strong>any insertions</strong> of rows or sections <strong>until after</strong> it has handled the deletions of rows or sections. This happens <strong>regardless of ordering of the insertion and deletion</strong> method calls.</p>
				<p>Deletions within an animation block specify which rows and sections in the <strong>original</strong> table should be removed; insertions specify which rows and sections should be added to the <strong>resulting</strong> table.</p>
				</blockquote>
				</dd>
				<dt class="cite"> 引用元: <a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html">Table View Programming Guide for iPhone OS: Inserting and Deleting Rows and Sections</a>（強調は引用者による）</dt>
				</dl>
				<p>この文章をまとめてみました。<br />
				（前提条件としてbeginUpdates/endUpdatesで囲まれている中では）</p>
				<ul>
				<li>deleteRowsAtIndexPaths:withRowAnimation:メソッドをinsertRowsAtIndexPaths:withRowAnimation:メソッドの前に呼ぶことは必須ではない（not the order）。</li>
				<li>実際のcellの追加は削除のあとに行われる。上記メソッドの呼び出し順序は影響を及ぼさない（regardless of ordering of the insertion and deletion）。</li>
				<li>削除時のindexPathにはbeginUpdates呼び出し前、元々の（original）テーブルに対するものを指定し、追加時は削除後の結果となる（resulting）テーブルに対するものを指定する。</li>
				</ul>
				<p>このような仕組みにすることで、以下のページに書かれているように1つのcellを削除するごとにindexPathを調整することが必要なく、削除を直感的に行うことが出来ます。<br />
				<a target="_blank" href="http://iphone-dev.g.hatena.ne.jp/tokorom/20090604/1244083883">テーブルのセルの削除や追加にbeginUpdates/endUpdatesは必要か(2) &#8211; iPhoneアプリ開発まっしぐら★ &#8211; iPhoneアプリ開発グループ</a></p>
				<p>ということで、beginUpdates/endUpdatesメソッドはcellをいっぺんに追加/削除したい場合に使えばよい！ということになります。</p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html">Table View Programming Guide for iPhone OS: Inserting and Deleting Rows and Sections</a></li>
				<li><a target="_blank" href="http://iphone-dev.g.hatena.ne.jp/tokorom/20090603/1244008956">テーブルのセルの削除や追加にbeginUpdates/endUpdatesは必要か(1) &#8211; iPhoneアプリ開発まっしぐら★ &#8211; iPhoneアプリ開発グループ</a></li>
				<li><a target="_blank" href="http://iphone-dev.g.hatena.ne.jp/tokorom/20090604/1244083883">テーブルのセルの削除や追加にbeginUpdates/endUpdatesは必要か(2) &#8211; iPhoneアプリ開発まっしぐら★ &#8211; iPhoneアプリ開発グループ</a></li>
				<li><a target="_blank" href="http://www.cocoalife.net/2008/12/post_767.html">cocoa*life &#8211; UITableViewCellを削除ボタンを使って削除する</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/04/post_543.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animationで遊んでみる (2)</title>
		<link>http://www.cocoalife.net/2010/03/post_545.html</link>
		<comments>http://www.cocoalife.net/2010/03/post_545.html#comments</comments>
		<pubDate>Wed, 24 Mar 2010 03:58:42 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=545</guid>
		<description><![CDATA[				以下はCore Animationで遊んでみる (2) &#124; アクトインディ技術部隊報告書と同じものです。
				以前のエントリに引き続き、Core Animationで少し遊んでみたいと思います。
				これも簡単にできるフェード処理です。
				以前のエントリと同様、QuartzCore.frameworkをincludeし
				#import &#60;QuartzCore/QuartzCore.h&#62;
とimportすることが必要です。
さて実際にフェード処理を記述してみましょう。
たとえば、hogeViewというViewをフェードアウトしてみます。
CATransition    *transition;
transition = [CATransition animation];

// トランジション時間の設定（これだと1秒）。
[transition setDuration:1.0f];

// トランジションの種類の設定、今回はフェード。
[transition setType:kCATransitionFade];

// トランジション中に起こす処理を記述。
[hogeView setHidden:YES];

// トランジションを実行。
[[[self view] layer] addAnimation:transition forKey:@&#34;layerAnimation&#34;];
				フェードインの時はsetHiddenをNoですね。
				この方法を用いて、もう一つサンプルを書いてみます。
				UINavigationItemのright/leftButtonItemを設定する際にはanimated:YESとすることでフェードイン/アウトしてくれますが、TitleViewはそのような項目はないのでこの方法を使えないかと思いやってみたらできました。
				TitleViewにはUISegmentedControlを設定することにします。
				CATransition    *transition;
transition = [CATransition animation];

[transition setDuration:1.0f];
[transition setType:kCATransitionFade];
[[self navigationItem] setTitleView:segmentedControl];
[[[[self navigationController] navigationBar] layer] addAnimation:transition forKey:@&#34;layerAnimation&#34;];
]]></description>
			<content:encoded><![CDATA[				<p>以下は<a target="_blank" href="http://tech.actindi.net/3478391136">Core Animationで遊んでみる (2) | アクトインディ技術部隊報告書</a>と同じものです。</p>
				<p><a href="http://www.cocoalife.net/2010/03/post_471.html">以前のエントリ</a>に引き続き、Core Animationで少し遊んでみたいと思います。<br />
				これも簡単にできるフェード処理です。</p>
				<p><a href="http://www.cocoalife.net/2010/03/post_471.html">以前のエントリ</a>と同様、QuartzCore.frameworkをincludeし</p>
				<pre>#import &lt;QuartzCore/QuartzCore.h&gt;</pre>
<p>とimportすることが必要です。</p>
<p>さて実際にフェード処理を記述してみましょう。<br />
たとえば、hogeViewというViewをフェードアウトしてみます。</p>
<pre class="brush: objc;">CATransition    *transition;
transition = [CATransition animation];

// トランジション時間の設定（これだと1秒）。
[transition setDuration:1.0f];

// トランジションの種類の設定、今回はフェード。
[transition setType:kCATransitionFade];

// トランジション中に起こす処理を記述。
[hogeView setHidden:YES];

// トランジションを実行。
[[[self view] layer] addAnimation:transition forKey:@&quot;layerAnimation&quot;];</pre>
				<p>フェードインの時はsetHiddenをNoですね。</p>
				<p>この方法を用いて、もう一つサンプルを書いてみます。<br />
				UINavigationItemのright/leftButtonItemを設定する際にはanimated:YESとすることでフェードイン/アウトしてくれますが、TitleViewはそのような項目はないのでこの方法を使えないかと思いやってみたらできました。</p>
				<p>TitleViewにはUISegmentedControlを設定することにします。</p>
				<pre class="brush: objc;">CATransition    *transition;
transition = [CATransition animation];

[transition setDuration:1.0f];
[transition setType:kCATransitionFade];
[[self navigationItem] setTitleView:segmentedControl];
[[[[self navigationController] navigationBar] layer] addAnimation:transition forKey:@&quot;layerAnimation&quot;];</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/03/post_545.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animationで遊んでみる (1)</title>
		<link>http://www.cocoalife.net/2010/03/post_471.html</link>
		<comments>http://www.cocoalife.net/2010/03/post_471.html#comments</comments>
		<pubDate>Wed, 24 Mar 2010 03:51:40 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=471</guid>
		<description><![CDATA[				以下はCore Animationで遊んでみる (1) &#124; アクトインディ技術部隊報告書と同様のものです。
				Mac OS X 10.5 Leopardの目玉機能の一つはCore Animationでした。
				Appleの触れ込みによると、Core Animationを利用すると簡単にアニメーション処理を追加することができるそうです。
				なんですが、アニメーションではないところでも、便利に使うことができます。
				今回はiPhone SDKを用いて、そのちょっと便利な使い方を書こうと思います。
				以下のサンプルでは全部
				QuartzCore.frameworkをincludeし
				#import &#60;QuartzCore/QuartzCore.h&#62;
とimportをすることが必要です。
UIViewを角丸にする
UIViewを角丸にするのはとても簡単です。
[[view layer] setCornerRadius:10.0];
[view setClipsToBounds:YES];
				UIViewに枠線を追加する
				[[view layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
[[view layer] setBorderWidth:1.0];
				setBorderColorメッセージの引数はCGColorなので、上記のようにUIColorからCGColorに変更してあげる必要があります。
]]></description>
			<content:encoded><![CDATA[				<p>以下は<a target="_blank" href="http://tech.actindi.net/3477781577">Core Animationで遊んでみる (1) | アクトインディ技術部隊報告書</a>と同様のものです。</p>
				<p>Mac OS X 10.5 Leopardの目玉機能の一つはCore Animationでした。<br />
				Appleの触れ込みによると、Core Animationを利用すると簡単にアニメーション処理を追加することができるそうです。</p>
				<p>なんですが、アニメーションではないところでも、便利に使うことができます。<br />
				今回はiPhone SDKを用いて、そのちょっと便利な使い方を書こうと思います。</p>
				<p>以下のサンプルでは全部<br />
				QuartzCore.frameworkをincludeし</p>
				<pre>#import &lt;QuartzCore/QuartzCore.h&gt;</pre>
<p>とimportをすることが必要です。</p>
<h2>UIViewを角丸にする</h2>
<p>UIViewを角丸にするのはとても簡単です。</p>
<pre class="brush: objc;">[[view layer] setCornerRadius:10.0];
[view setClipsToBounds:YES];</pre>
				<h2>UIViewに枠線を追加する</h2>
				<pre class="brush: objc;">[[view layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
[[view layer] setBorderWidth:1.0];</pre>
				<p>setBorderColorメッセージの引数はCGColorなので、上記のようにUIColorからCGColorに変更してあげる必要があります。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/03/post_471.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>UITextFieldに入力されている文字数を動的に、非同期に数える。</title>
		<link>http://www.cocoalife.net/2010/03/post_546.html</link>
		<comments>http://www.cocoalife.net/2010/03/post_546.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 02:17:12 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=546</guid>
		<description><![CDATA[				以下はUITextFieldに入力されている文字数を動的に、非同期に数える。 &#124; アクトインディ技術部隊報告書と同じものです。
				とあるUITextFieldによる入力フォームと、UIBarButtonItemによる「完了」ボタンがある画面を考えます。
				今回のエントリの目的はUITextFieldに文字が入力されていない、つまり空であるときは、「完了」ボタンを表示しない画面を作成するということです。
				ポイントはUIControlEventEditingChangedイベントを使うこと。
				最初はUITextFieldDelegateのtextField:shouldChangeCharactersInRange:replacementString:とかを使用することを考えましたが、文字を消去したときにボタンが消えない等々うまくいきませんでした。
				サンプルコードを書いてみます。
				- (void)setupUserInterface
{
    UIView      *contentView;
    UITextField *textField;

    contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self setView:contentView];
    [contentView release];

    doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
         [...]]]></description>
			<content:encoded><![CDATA[				<p>以下は<a target="_blank" href="http://tech.actindi.net/3476570782">UITextFieldに入力されている文字数を動的に、非同期に数える。 | アクトインディ技術部隊報告書</a>と同じものです。</p>
				<p>とあるUITextFieldによる入力フォームと、UIBarButtonItemによる「完了」ボタンがある画面を考えます。</p>
				<p>今回のエントリの目的はUITextFieldに文字が入力されていない、つまり空であるときは、「完了」ボタンを表示しない画面を作成するということです。</p>
				<p>ポイントはUIControlEventEditingChangedイベントを使うこと。<br />
				最初はUITextFieldDelegateのtextField:shouldChangeCharactersInRange:replacementString:とかを使用することを考えましたが、文字を消去したときにボタンが消えない等々うまくいきませんでした。</p>
				<p>サンプルコードを書いてみます。</p>
				<pre class="brush: objc;">- (void)setupUserInterface
{
    UIView      *contentView;
    UITextField *textField;

    contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self setView:contentView];
    [contentView release];

    doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                               target:self
                                                               action:@selector(respondsToDoneButtonTouchDown:)];

    textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
    [contentView addSubview:textField];
    [textField release];
    [textField addTarget:self
                  action:@selector(respondsToEditingChanged:)
        forControlEvents:UIControlEventEditingChanged];
}

- (void)respondsToEditingChanged:(id)sender
{
    if ([sender isKindOfClass:[UITextField class]])
    {
        // 本当はsenderを用いずにメンバ変数とかにしておけばいいのだけれど、今回はあえて型変換をしてみる。
        if ([[(UITextField *)sender text] length])
        {
            [[self navigationItem] setRightBarButtonItem:doneButton animated:YES];
        }
        else
        {
            [[self navigationItem] setRightBarButtonItem:nil animated:YES];
        }
    }
}</pre>
				<p>参考<br />
				<a target="_blank" href="http://groups.google.co.jp/group/iphonesdkdevelopment/browse_thread/thread/0cc9032a397a02ff">Disable button if textField is empty &#8211; iPhone SDK Development</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/03/post_546.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhoneによる位置情報関係のまとめ</title>
		<link>http://www.cocoalife.net/2010/01/post_498.html</link>
		<comments>http://www.cocoalife.net/2010/01/post_498.html#comments</comments>
		<pubDate>Sun, 31 Jan 2010 14:48:53 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=498</guid>
		<description><![CDATA[				以下はiPhoneによる位置情報関係のまとめ &#124; アクトインディ技術部隊報告書と同様のものです。
				今回も前回のGeohashに引き続き、位置情報に関する内容です。
				ググれば出てくる内容なので、新しいことはなんにもないのが申し訳ないところです。
				位置情報に関するライブラリは
				
				CoreLocation
				MapKit
				
				などがあります。
				GPSで現在位置を取得するにはCoreLocationを使用し、地図を表示したり現在地の大まかな住所を取得するためにはMapKitを使用します。
				GPSで現在位置を取得するには
				CoreLocationではCLLocationManagerDelegateを実装し
				
- (void)setup
{
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    if ([locationManager locationServicesEnabled])
    {
        [locationManager setDelegate:self];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        [locationManager setDistanceFilter:kCLDistanceFilterNone];
    }
}

- (void)locationManager:(CLLocationManager [...]]]></description>
			<content:encoded><![CDATA[				<p>以下は<a target="_blank" href="http://tech.actindi.net/3473583175">iPhoneによる位置情報関係のまとめ | アクトインディ技術部隊報告書</a>と同様のものです。</p>
				<p>今回も前回のGeohashに引き続き、位置情報に関する内容です。<br />
				ググれば出てくる内容なので、新しいことはなんにもないのが申し訳ないところです。</p>
				<p>位置情報に関するライブラリは</p>
				<ul>
				<li>CoreLocation</li>
				<li>MapKit</li>
				</ul>
				<p>などがあります。</p>
				<p>GPSで現在位置を取得するにはCoreLocationを使用し、地図を表示したり現在地の大まかな住所を取得するためにはMapKitを使用します。</p>
				<h2>GPSで現在位置を取得するには</h2>
				<p>CoreLocationではCLLocationManagerDelegateを実装し</p>
				<pre class="brush: objc;">
- (void)setup
{
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    if ([locationManager locationServicesEnabled])
    {
        [locationManager setDelegate:self];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        [locationManager setDistanceFilter:kCLDistanceFilterNone];
    }
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@&quot;%@&quot;, newLocation);
}
</pre>
				<p>このようにすればLogに現在地の情報が取得できます。</p>
				<h2>地図を表示するには</h2>
				<pre class="brush: objc;">
- (void)setup
{
    CGRect screen = [[UIScreen mainScreen] bounds];
    MKMapView *mapView = [[MKMapView alloc] initWithFrame:screen];
    [[self view] addSubview:mapView];
    [mapView release];

    MKCoordinateRegion  region;
    region.center = [location coordinate];
    region.span.latitudeDelta = 0.005;
    region.span.longitudeDelta = 0.005;
    [mapView setRegion:region animated:YES];
}
</pre>
				<p>とすれば、locationで指定した座標に移動します。</p>
				<h2>現在地を取得するには</h2>
				<p>MKReverseGeocoderDelegateを実装し</p>
				<pre class="brush: objc;">
- (void)setup
{
    MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:[location coordinate]];
    [reverseGeocoder setDelegate:self];
    [reverseGeocoder start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
    NSLog(@&quot;%@&quot;, [placemark title]);
}
</pre>
				<p>とすることで取得することができます。<br />
				すべてのAPIが非常にシンプルに作られているので、使用するのは非常に簡単です。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/01/post_498.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
