Xcode3.3.2でMKMapViewを使う

久しぶりに書きます。スパムよけの話を書いたら3000件も食らいました。笑ってやって下さい。投稿者が同じだったので一発で削除できましたが。
今ちょっとiPhone/iPod Touch用アプリケーションを作っているんですが、地図を出すだけで1時間くらいハマったのでやり方を書きます。画像とか撮るほど善人ではないので全部文字でいきます。ある程度Xcode/IBを触ったことがある人向けですかね。よく分からないところがあったらよその解説サイト(こことか)の方が画像付きで親切で善人です。
まず、Viewテンプレートでプロジェクトを起こします。名前はMyAppとします。Xcode中のResources/MyAppViewConrtoller.xibをダブルクリックしてInterfaceBuilderを出してやります。
そしたらViewというタイトルのiPhoneっぽいウインドウが出ますから、メニュー->Tools->Libraryでライブラリウインドウを開きます。するとLibraryウインドウの真ん中あたりにMap Viewというのがあるのでそれを丸ごとViewウインドウにドラッグ&ドロップして位置大きさを調整してあげます。
しかしこのMap Viewは実体がないのでコードで記述してあげます。
MyAppViewController.h
#import <MapKit/MapKit.h>
...
@interface MyViewController :
UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView;
}
@property (nonatomic, retain) MKMapView *mapView;
まあヘッダはこんな感じです。ここでMapKit/MapKit.hをimportするのと、<MKMapViewDelegate>を記述しわすれないようにしましょう。ここで20分くらいハマりました。次は実装しましょう。といっても大したことはしません。
MyAppViewController.m
#import "MyAppViewController.h"
@synthesize mapView;
:
:
- (void)dealloc {
[mapView release];
[super dealloc];
}
こんくらいです。mapViewのreleaseはWarningが出るので多分間違ってます。誰か正解を教えてください。
次。またMyAppViewController.xibをダブルクリックして、InterfaceBuilderに移ります。MyAppViewController.xibというウインドウがあるので、そこのFile’s Ownerを右クリックします。すると、Outletsの中にmapViewという記述があるはずなので(無ければ宣言定義のどこかが間違っている)、その右端の白い丸をクリックしたままViewウインドウのMKMapViewというところにドロップしてやります。
mapView - Map View
のように表示が変わったら成功です。
ビルドして実行してみて下さい。うまく表示されたかたはここではおしまいです。大抵のチュートリアルはここまでです。しかし落とし穴がありました。フレームワークの呼び出しです。
もう一度XCodeのメインウインドウに戻って、左カラムのFrameworksを開けて下さい。MapKit.frameworkが出た人はそのままでいいです。が、ビルドして上手く行かなかった人はこれが抜けてると思います。Frameworksフォルダを右クリック(ノートの人は2本指+クリック)して、追加->既存のフレームワーク…を選びます。するとフレームワークの一覧が出るので、MapKit.frameworkを選択して追加ボタン。これで動くはずです。
自分がやってみたところ、なぜかMapKit.frameworkフォルダがトップ階層に放り出されてしまったので自分でFrameworksフォルダにドラッグ&ドロップしたらうまくいきました。
この、フレームワークをインポートするという解説が日本語のサイトには見当たらなかったのでメモとして書いておきます。
2011/12/09 - 18:59:15 -
You should check this out
[…] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well […]…
2011/12/09 - 20:25:24 -
Blogs ou should be reading
[…]Here is a Great Blog You Might Find Interesting that we Encourage You[…]…
2011/12/10 - 00:06:36 -
Recent Blogroll Additions…
[…]usually posts some very interesting stuff like this. If you’re new to this site[…]…
2011/12/10 - 00:29:06 -
Looking around
I like to look in various places on the online world, regularly I will just go to Stumble Upon and follow thru
2011/12/10 - 06:03:16 -
Websites we think you should visit
[…]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[…]…
2011/12/10 - 12:21:08 -
Recent Blogroll Additions…
[…]usually posts some very interesting stuff like this. If you’re new to this site[…]…
2011/12/10 - 22:07:29 -
Websites you should visit
[…]below you’ll find the link to some sites that we think you should visit[…]…
2011/12/10 - 23:42:33 -
Related…
[…]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[…]…
2011/12/11 - 00:37:32 -
Online Article…
[…]The information mentioned in the article are some of the best available […]…
2011/12/11 - 03:42:33 -
The best website……
[…]here are some links to sites that we link to because we think they are worth visiting[…]……
2011/12/11 - 18:03:35 -
Recommeneded websites
[…]Here are some of the sites we recommend for our visitors[…]…
2011/12/11 - 20:34:02 -
aas
raiders jerseysIt isn’t really easy to shop at the second or third day of UGG sale with a number of other people fighting with you to your same boot.moncler mens jacket
2011/12/12 - 02:47:57 -
Awesome website
[…]the time to read or visit the content or sites we have linked to below the[…]…
2011/12/12 - 10:19:46 -
Read was interesting, stay in touch…
[…]please visit the sites we follow, including this one, as it represents our picks from the web[…]…
2011/12/12 - 12:42:54 -
Awesome website
[…]the time to read or visit the content or sites we have linked to below the[…]…
2011/12/12 - 16:05:41 -
popular dating sites
magnificent points altogether, you simply gained a new reader. What would you suggest about your post that you made some days ago? Any positive?
2011/12/12 - 18:28:10 -
Links
[…]Sites of interest we have a link to[…]…
2011/12/12 - 19:54:39 -
Websites we think you should visit
[…]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[…]…
2011/12/12 - 23:29:40 -
You should check this out
[…] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well […]…
2011/12/14 - 06:06:54 -
Check this out
[…]unique writing style that I like[…]
2011/12/14 - 08:27:44 -
You should check this out
[…] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well […]…
2011/12/14 - 15:43:56 -
Related…
[…]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[…]…
2011/12/14 - 19:34:21 -
Recent Blogroll Additions…
[…]usually posts some very interesting stuff like this. If you’re new to this site[…]…
2011/12/15 - 17:10:14 -
Cool sites
[…]we came across a cool site that you might enjoy. Take a look if you want[…]…
2011/12/15 - 18:59:58 -
christian dating
Thanks a lot for the helpful write-up. It is also my opinion that mesothelioma has an extremely long latency interval, which means that the signs of the disease may well not emerge until finally 30 to 50 years after the original exposure to asbestos. …
2011/12/15 - 19:40:25 -
Check this out
[…] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[…]…
2011/12/15 - 20:19:36 -
Further Resources
[…] If you’re trying to find further information on this topic, more info on this issue was published a while ago on […]
2011/12/15 - 21:43:30 -
Further Resources
[…] In case you are looking for more in detail info about this issue, more information about this problem was published at […]
2011/12/16 - 07:36:26 -
Websites worth visiting
[…]here are some links to sites that we link to because we think they are worth visiting[…]…
2011/12/16 - 10:27:17 -
Blogs ou should be reading
[…]Here is a Great Blog You Might Find Interesting that we Encourage You[…]…