콜 아웃에 테이블의 "clickable"플래그를 기반으로 액세서리 버튼이 있는지 여부를 제어하려면 clickable
속성을 주석 클래스에 추가하고 주석을 추가 할 때 설정하는 것이 좋습니다. 그런 다음 viewForAnnotation
메소드에서 주석보기를 만들 때이 속성을 확인할 수 있습니다.
은 (당신이
addAnnotation
를 호출 할 때 즉.) 현재
MKPointAnnotation
같은 미리 정의 된 클래스를 사용하는 경우, 당신은
MKAnnotation
프로토콜을 구현하는 대신 자신 만의 클래스를 정의해야합니다지도보기에 주석을 추가하려면 . 맞춤 클래스가 이미있는 경우
clickable
속성을 추가하십시오. 여기
//CustomAnnotation.h...
@interface CustomAnnotation : NSObject<MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, assign) int annotationId;
@property (nonatomic, assign) BOOL clickable;
@end
//CustomAnnotation.m...
@implementation CustomAnnotation
@synthesize coordinate;
@synthesize title;
@synthesize subtitle;
@synthesize annotationId;
@synthesize clickable;
- (void)dealloc {
[title release];
[subtitle release];
[super dealloc];
}
@end
이 (당신의 SQL 행에서 올 것이다 주석 속성에 대한 실제 값)이 주석을 작성하고 추가 할 방법의 예 : 여기
사용자 정의 주석 클래스의 예
CustomAnnotation *ca1 = [[CustomAnnotation alloc] init];
ca1.annotationId = 1;
ca1.coordinate = CLLocationCoordinate2DMake(lat1,long1);
ca1.title = @"clickable";
ca1.subtitle = @"clickable subtitle";
ca1.clickable = YES;
[myMapView addAnnotation:ca1];
[ca1 release];
CustomAnnotation *ca2 = [[CustomAnnotation alloc] init];
ca2.annotationId = 2;
ca2.coordinate = CLLocationCoordinate2DMake(lat2,long2);
ca2.title = @"not clickable";
ca2.subtitle = @"not clickable subtitle";
ca2.clickable = NO;
[myMapView addAnnotation:ca2];
[ca2 release];
그런 다음 viewForAnnotation
는 다음과 같이 표시됩니다
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *reuseId = @"CustomAnnotation";
MKPinAnnotationView* customPinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (customPinView == nil) {
customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId] autorelease];
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
}
else {
customPinView.annotation = annotation;
}
CustomAnnotation *ca = (CustomAnnotation *)annotation;
if (ca.clickable)
customPinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
else
customPinView.rightCalloutAccessoryView = nil;
return customPinView;
}
마지막으로, 당신은 calloutAccessoryControlTapped
대리자 메서드에있는 버튼을 눌러를 처리하고 사용자 정의 주석의 속성에 액세스 할 수 있습니다 :
당신이 MKAnnotation 객체를 생성하는 데 사용하는 어떤 클래스
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
CustomAnnotation *ca = (CustomAnnotation *)view.annotation;
NSLog(@"annotation tapped, id=%d, title=%@", ca.annotationId, ca.title);
}
? 맞춤 클래스 또는 MKPointAnnotation과 같이 미리 정의 된 클래스입니까? – Anna
난이 사용 MKPinAnnotationView customPinView * = [[[MKPinAnnotationView의 ALLOC]을 \t \t \t \t \t \t \t \t \t \t \t \t initWithAnnotation : 주석 reuseIdentifier : UserAnnotationId] 오토 릴리즈]; customPinView.pinColor = MKPinAnnotationColorPurple; customPinView.animatesDrop = YES; customPinView.canShowCallout = YES; customPinView.rightCalloutAccessoryView = [UIButton buttonWithType : UIButtonTypeDetailDisclosure]; return customPinView; – asnanak