そのため、デフォルトの赤い注釈はシミュレーターにまったく問題なく表示されますが、カスタム注釈 MyPin は表示されません。これは NSMutableArray と関係があると思いますか? もしそうなら、私はそれを回避する方法がよくわかりませんか?
うまくいけば、いくつかの光を当てることができるグルがフォーラムにいることを願っています(うまくいけば、それは本当に初心者のエラーではありません。私は過去2時間これを調べましたが、何も見えません. )
#import "UKFlightsEuropeMap.h"
#import "Annotation.h"
@interface UKFlightsEuropeMap ()
@end
@implementation UKFlightsEuropeMap
@synthesize europeMapView;
//Define the Long and Lat.
#define EUROPE_LATITUDE 47.3690;
#define EUROPE_LONGITUDE 8.5380;
#define LONDON_LATITUDE 51.5171;
#define LONDON_LONGITUDE 0.1062;
#define PARIS_LATITUDE 48.8742;
#define PARIS_LONGITUDE 2.3470;
#define BRUSSELS_LATITUDE 50.75;
#define BRUSSELS_LONGITUDE 4.53333;
#define BERLIN_LATITUDE 52.5;
#define BERLIN_LONGITUDE 13.35;
#define THE_SPAN 0.01f;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[europeMapView setDelegate:self];
// Do any additional setup after loading the view.
//CREATE MY REGION
MKCoordinateRegion myRegion;
//SET CENTRE
CLLocationCoordinate2D center;
center.latitude = EUROPE_LATITUDE;
center.longitude = EUROPE_LONGITUDE;
//SET SPAN (ZOOM)
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
myRegion.center = center;
myRegion.span = span;
//Set our europeMapView
[europeMapView setRegion:myRegion animated:YES];
//Annotation
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
Annotation * myAnn;
//London Annotation
myAnn = [[Annotation alloc] init];
location.latitude = LONDON_LATITUDE;
location.longitude = LONDON_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"London";
myAnn.subtitle = @"London City";
[locations addObject:myAnn];
//Paris Annotation
myAnn = [[Annotation alloc] init];
location.latitude = PARIS_LATITUDE;
location.longitude = PARIS_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"Paris";
myAnn.subtitle = @"City of Love";
[locations addObject:myAnn];
//Brussels Annotation
myAnn = [[Annotation alloc] init];
location.latitude = BRUSSELS_LATITUDE;
location.longitude = BRUSSELS_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"Brussels";
myAnn.subtitle = @"Brussels";
[locations addObject:myAnn];
//Berlin Annotation
myAnn = [[Annotation alloc] init];
location.latitude = BERLIN_LATITUDE;
location.longitude = BERLIN_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"Berlin";
myAnn.subtitle = @"Berlin";
[locations addObject:myAnn];
[self.europeMapView addAnnotations:locations];
}
//CUSTOMISE THE ANNOTATION CALLOUTS.
-(MKAnnotationView *) europeMapView:(MKMapView *)europeMapView viewForAnnotation: (id<MKAnnotation>)annotation { MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
MyPin.pinColor = MKPinAnnotationColorPurple;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[advertButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
MyPin.rightCalloutAccessoryView = advertButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop = TRUE;
MyPin.canShowCallout = YES;
return MyPin;
}
-(void)button:(id)sender {
NSLog(@"Button Pressed");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
よろしくお願いします。