0
ok私は注釈がうまく表示されていますが、小さなダイアログボックスを表示する方法を理解できません。注釈を作成するときは、次のようにします:注釈の上に詳細を表示する
Annotation *annot = [[Annotation alloc] init];
annot.coordinate = touchMapCoordinate;
annot.title = @"Location";
annot.subtitle = @"The address";
[self.mapView addAnnotation:annot];
もう一度、これは検索されますが、小さなダイアログボックスは表示されません。
私はデリゲートと何か関係があることを理解しています。リンゴのMapCalloutsのサンプルコードをダウンロードしたところ、アノテーションにデリゲートがどのように連絡したのか分かりませんでした。
ここに私のアノテーションクラス
Annotation.H
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Annotation : NSObject <MKAnnotation>{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D) c
title:(NSString *) t
subtitle:(NSString *) st;
-(void) moveAnnotation: (CLLocationCoordinate2D) newCoordinate;
-(NSString *)subtitle;
-(NSString *)title;
@end
Annotation.m
#import "Annotation.h"
@implementation Annotation
@synthesize coordinate = _coordinate;
@synthesize title = _title;
@synthesize subtitle = _subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t subtitle:(NSString *)st
{
coordinate = c;
self.title = t;
self.subtitle = st;
return self;
}
-(void)moveAnnotation:(CLLocationCoordinate2D)newCoordinate
{
coordinate = newCoordinate;
}
-(NSString *)subtitle {
return subtitle;
}
-(NSString *)title{
return title;
}
@end
は、ここに私がセットアップさdelagateです:
-(MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[Annotation class]])
{
static NSString *reuseId = @"customAnn";
MKAnnotationView *customAnnotationView = [aMapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (customAnnotationView == nil)
{
customAnnotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
UIImage *pinImage = [UIImage imageNamed:@"pin-green.png"];
[customAnnotationView setImage:pinImage];
customAnnotationView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
customAnnotationView.rightCalloutAccessoryView = rightButton;
}
customAnnotationView.annotation = annotation;
return customAnnotationView;
}
return nil;
}
をします場合は、情報をもっと必要とする私からのご連絡は、私に知らせて、事前に感謝してください!
マップビューのデリゲートを設定するにはどうすればよいですか? –
このように、右ですか?:@インターフェイスMapViewController:UIViewController –
はい。実際にmapViewのデリゲートプロパティを設定することを確認してください(mapView.delegate = self;) –