0

私は xcode を初めて使用します。マップを作成し、MutableArray を使用していくつかの注釈を追加しました。それらを 3 つのグループに分けて、3 つの異なるピンの色を使用してマップ上に表示したいと思います。私を助けることができるガイドへのURLを教えてください。「ifステートメント」と「annotationType」を作成しようとしましたが、正しく機能することができました。あなたが助けてくれるか、私にヒントを与えてくれることを願っています。

お時間をいただきありがとうございます。

ViewController.m

{

[super viewDidLoad];

[self.myMapView setDelegate:self];


MKCoordinateRegion myRegion;

CLLocationCoordinate2D center;
center.latitude = AMAR_LATITUDE;
center.longitude = AMAR_LONGITUDE;

MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;

myRegion.center = center;
myRegion.span = span;

[myMapView setRegion: myRegion animated: YES];

NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
Annotation *myAnn;
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
Annotation *myAnn;

myAnn = [[Annotation alloc] init];
location.latitude = TATU_LATITUDE;
location.longitude = TATU_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"Tante Tuli";
myAnn.subtitle =@"Amagerbrogade 161";
[locations addObject:myAnn];
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

MKPinAnnotationView *view =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
view.pinColor = MKPinAnnotationColorRed;
view.enabled = YES;
view.animatesDrop = YES;
view.canShowCallout = YES;
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return view;
}

注釈.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Annotation : NSObject <MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
- initWithPosition:(CLLocationCoordinate2D)coords;
@end

注釈.m

#import "Annotation.h"
@implementation Annotation;
@synthesize coordinate, title, subtitle;
- initWithPosition:(CLLocationCoordinate2D)coords; {
if (self = [super init]) {
    self.coordinate = coords;
}
return self;
}
@end

4行目を追加しようとしました:

注釈.h

@property (nonatomic, copy) NSString  *colortag;

注釈.m

@synthesize coordinate, title, subtitle, colortag;

ViewController.m

myAnn = [[Annotation alloc] init];
location.latitude = TATU.LATITUDE;
location.longitude = TATU.LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"name";
myAnn.subtitle =@"adr";
myAnn.colortag =@"purple";
[locations addObject:myAnn];

if ([[annotation colortag] isEqualToString:@"purple"])
view.pinColor = MKPinAnnotationColorPurple;

エラーが表示されます: セレクター 'colertag' の既知のインスタンス メソッドはありません:S

4

1 に答える 1

0

クラスAnnotationには、タイトル、サブタイトル、座標のプロパティがあります。4 番目を追加して、他の設定時に設定し、それを読み込んで、viewForAnnotation で色を設定するだけです。新しいプロパティを読み取る前に、パラメーターをクラスにキャストする必要がありannotationます (それがクラスのインスタンスであり、ユーザーの場所の注釈ではないことを確認した後)。

于 2013-04-14T08:22:12.537 に答える