我是 xcode 的新手——我制作了一张地图并使用 MutableArray 添加了一些注释。我想将它们分成 3 组,并使用 3 种不同的别针颜色在地图上显示它们。希望您能提供帮助或给我一个可以帮助我的指南的网址。我尝试制作一个“if 语句”和一个“annotationType”,但可以让它正常工作。希望你能帮助或给我一个提示。
感谢您的时间。
视图控制器.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
我试图添加第四行:
注释.h
@property (nonatomic, copy) NSString *colortag;
注释.m
@synthesize coordinate, title, subtitle, colortag;
视图控制器.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