おはようございます。
今回はMKMapViewの話です。
次回に、MKMapViewにPinをDropする話をするための前座です。
では、iPhoneアプリにMapを表示させましょう。
Mapは基本的に画面全部を使ったほうが見栄えが良いと思いますので、
UIViewControllerの上に描画していきます。
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController {
MKMapView *mapView;
}
@end
headerファイルは何も難しいことはありません。ただ、MKMapViewのインスタンスを宣言しているだけです。
#import <MapKit/MapKit.h>
#import "MapViewController.h"
@implementation MapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
// set map view
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:mapView];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
はい、ほとんど変更点はありません。
UIViewControllerのサブクラスのinitWithNibNameを少し変更しただけです。
これでMapが表示されるはずです・・・
次回もよろしくお願いします。
0 件のコメント:
コメントを投稿