2
我想更改MKMapView上顯示的標註。當我致電selectAnnotation不顯示標註
[self.mapView selectAnnotation:annotation animated:YES];
它將地圖拖到註釋中,但不顯示其標註。我如何獲得它以顯示標註?
我想更改MKMapView上顯示的標註。當我致電selectAnnotation不顯示標註
[self.mapView selectAnnotation:annotation animated:YES];
它將地圖拖到註釋中,但不顯示其標註。我如何獲得它以顯示標註?
設置註釋對象上的title
以及可選的subtitle
屬性。 MapKit將自動顯示標註。
@interface MyAnnotation : NSObject <MKAnnotation> {
NSString *title;
NSString *subtitle;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
及實施,
#import "MyAnnotation.h"
@implementation MyAnnotation
@synthesize title, subtitle;
@end
用法,
MyAnnotation *foo = [[MyAnnotation alloc] init];
foo.title = @"I am Foo";
foo.subtitle = "I am jus' a subtitle";
應實現MKAnnotation委託方法
-(MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *AnnotationViewIdentifier = @"AnnotationViewIdentifier";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewIdentifier];
if (annotationView == nil)
{
annotationView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationViewIdentifier]autorelease];
}
annotationView.canShowCallout = YES;
return annotationView;
}
這並不工作(注意,我的註釋我自己的類MKAnnotation的子類,所以我有我自己的標題得主。你是怎麼建議我設置標題的? – user605957
你的自定義類應該實現協議'MKAnnotation'。在你的課堂中爲'title'和'subtitle'添加一個屬性。將添加一個完整的示例。 – Anurag