我尝试管理注释,并在选择 PIN 时在视图右侧显示一个信息按钮,我的相关代码是这样的:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenPin"];
if ([annotation isKindOfClass:[ManageAnnotations class]]) {
static NSString* identifier = @"ManageAnnotations";
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
if (newAnnotation==nil) {
newAnnotation=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
}else {
newAnnotation.annotation=annotation;
}
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
newAnnotation.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeInfoLight];
return newAnnotation;
}else {
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
return newAnnotation;
}
ManageAnnotations.m :
@implementation ManageAnnotations
@synthesize pinColor;
@synthesize storeName=_storeName;
@synthesize storeAdress=_storeAdress;
@synthesize coordinate=_coordinate;
-(id)initWithTitle:(NSString*)storeName adress:(NSString*)storeAdress coordinate:(CLLocationCoordinate2D)coordinate{
if((self=[super init])){
_storeName=[storeName copy];
_storeAdress=[storeAdress copy];
_coordinate=coordinate;
}
return self;
}
-(NSString*)title{
return _storeName;
}
-(NSString*)subtitle{
return _storeAdress;
}
ManageAnnotations.h
@interface ManageAnnotations : NSObject<MKAnnotation>{
NSString *_storeName;
NSString *_storeAdress;
CLLocationCoordinate2D _coordinate;
}
//
@property(nonatomic,assign)MKPinAnnotationColor pinColor;
@property(nonatomic, readonly, copy)NSString *storeName;
@property(nonatomic, readonly, copy)NSString *storeAdress;
@property(nonatomic,readonly)CLLocationCoordinate2D coordinate;
//
-(id)initWithTitle:(NSString*)storeName adress:(NSString*)storeAdress coordinate:(CLLocationCoordinate2D)coordinate;
//
PIN 码在地图上正确显示,但视图右侧没有信息按钮。我错过了什么吗?