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フォルダにドラッグ&ドロップしたらうまくいきました。

この、フレームワークをインポートするという解説が日本語のサイトには見当たらなかったのでメモとして書いておきます。

30 件のコメント - “Xcode3.3.2でMKMapViewを使う”

  1. guelph dentist のコメント

    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 […]…

  2. Corona Property Management のコメント

    Blogs ou should be reading

    […]Here is a Great Blog You Might Find Interesting that we Encourage You[…]…

  3. gift baskets toronto のコメント

    Recent Blogroll Additions…

    […]usually posts some very interesting stuff like this. If you’re new to this site[…]…

  4. Solar Panels のコメント

    Looking around

    I like to look in various places on the online world, regularly I will just go to Stumble Upon and follow thru

  5. people planking のコメント

    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[…]…

  6. addicting games.com のコメント

    Recent Blogroll Additions…

    […]usually posts some very interesting stuff like this. If you’re new to this site[…]…

  7. affordable backlinks のコメント

    Websites you should visit

    […]below you’ll find the link to some sites that we think you should visit[…]…

  8. hawke scopes のコメント

    Related…

    […]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[…]…

  9. presentacion telematica renta のコメント

    Online Article…

    […]The information mentioned in the article are some of the best available […]…

  10. Cucumber Salad Recipe のコメント

    The best website……

    […]here are some links to sites that we link to because we think they are worth visiting[…]……

  11. Dog Washing Tub のコメント

    Recommeneded websites

    […]Here are some of the sites we recommend for our visitors[…]…

  12. how to get over someone のコメント

    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

  13. Sophia Allison のコメント

    Awesome website

    […]the time to read or visit the content or sites we have linked to below the[…]…

  14. Escortservice のコメント

    Read was interesting, stay in touch…

    […]please visit the sites we follow, including this one, as it represents our picks from the web[…]…

  15. Mesothelioma のコメント

    Awesome website

    […]the time to read or visit the content or sites we have linked to below the[…]…

  16. dating site bio cats のコメント

    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?

  17. AMG Services のコメント

    Links

    […]Sites of interest we have a link to[…]…

  18. AMG Services のコメント

    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[…]…

  19. AMG Services のコメント

    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 […]…

  20. Gemini Cooker Jamie Oliver Runs Into Trouble in West Virginia のコメント

    Check this out

    […]unique writing style that I like[…]

  21. online tv pc のコメント

    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 […]…

  22. design のコメント

    Related…

    […]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[…]…

  23. nursery wall decals のコメント

    Recent Blogroll Additions…

    […]usually posts some very interesting stuff like this. If you’re new to this site[…]…

  24. sciatic nerve pain のコメント

    Cool sites

    […]we came across a cool site that you might enjoy. Take a look if you want[…]…

  25. facebookofsex のコメント

    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. …

  26. credit card relief のコメント

    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[…]…

  27. Augenlaser Operation のコメント

    Further Resources

    […] If you’re trying to find further information on this topic, more info on this issue was published a while ago on […]

  28. Gentest のコメント

    Further Resources

    […] In case you are looking for more in detail info about this issue, more information about this problem was published at […]

  29. laptop repair mississauga のコメント

    Websites worth visiting

    […]here are some links to sites that we link to because we think they are worth visiting[…]…

  30. Solicitor Glasgow のコメント

    Blogs ou should be reading

    […]Here is a Great Blog You Might Find Interesting that we Encourage You[…]…

コメントをどうぞ。

使用できる XHTML タグ : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>