2012-04-16 8 views
0

- 私:MKAnnotation doesn'tトリガーピンポイントドロー法

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 

#import <Foundation/Foundation.h> 
#import <MapKit/MapKit.h> 

@interface ContactDetailAnnotation : NSObject <MKAnnotation> 

- (id) initWithLatitude:(CLLocationDegrees) lat longitude:(CLLocationDegrees) lng; 
- (id) initWithCoordinate:(CLLocationCoordinate2D) coordinateArg; 

@property (unsafe_unretained) CLLocationDegrees latitude; 
@property (unsafe_unretained) CLLocationDegrees longitude; 
@property (unsafe_unretained, nonatomic) CLLocationCoordinate2D coordinate; 

@end 

問題は方法であります私のポイントを描画するために使用されていないtrigeredされています。私は

self.myMap.showsUserLocation = TRUE;  

を使用する場合は 方法はtrigeredされているので、問題は、私が作成したクラスでなければなりません。

マイ.M

#import "ContactDetailAnnotation.h" 

@implementation ContactDetailAnnotation 

@synthesize latitude = _latitude, longitude = _longitude, coordinate = _coordinate; 

- (id) initWithCoordinate:(CLLocationCoordinate2D) coordinateArg 
{ 
    self.coordinate = coordinateArg; 

    return self; 
} 

- (id) initWithLatitude:(CLLocationDegrees)lat longitude:(CLLocationDegrees)lng 
{ 
    self.latitude = lat; 
    self.longitude = lng; 

    return self; 
} 

- (CLLocationCoordinate2D) coordinate 
{ 
CLLocationCoordinate2D coord = {self.latitude, 
           self.longitude}; 
return coord; 
} 

@end 
+0

' - (CLLocationCoordinate2D)coordinate'メソッドをオーバーライドする必要はありません。 –

+0

そのメソッドを削除するとクラッシュします。 – bruno

答えて

0

あなたはMapViewののannotations配列にあなたの注釈を追加しましたか?

編集

は、ここで私のために働いている最低限の実装です:

MyAnnotation.h:

#import <Foundation/Foundation.h> 
#import <Mapkit/Mapkit.h> 

@interface MyAnnotation : NSObject <MKAnnotation> 
{ 
    CLLocationCoordinate2D coordinate; 
} 

@property (nonatomic) CLLocationCoordinate2D coordinate; 

- (id) initWithCoordinate:(CLLocationCoordinate2D)aCoordinate; 

@end 

MyAnnotation.m

#import "MyAnnotation.h" 

@implementation MyAnnotation 

@synthesize coordinate; 

- (id) initWithCoordinate:(CLLocationCoordinate2D)aCoordinate 
{ 
    coordinate = aCoordinate; 
    return self; 
} 

@end 

マイ見ますコントローラー:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    CLLocationCoordinate2D coordinate = {42.149,-74.9384}; 
    MyAnnotation *myAnnotation = [[MyAnnotation alloc] initWithCoordinate:coordinate]; 
    [self.mapView addAnnotation:myAnnotation]; 
} 

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKAnnotationView *annotationView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"Identifier"]; 
    if (annotationView == nil) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Identifier"]; 
    } 
    return annotationView; 
} 
+0

はい[self.myMap addAnnotation:self.ContactDetailAnnotation]; – bruno

+0

これらのinitメソッドとインスタンス変数をすべて取り出し、 'setCoordinate:'を使って座標を設定してみてください。また、アノテーションを 'annotations'配列に記録して、それが何を含んでいるかを確認してください。 –

+0

ああ、その 'initWithLatitude:longitude:'を使って実際にアノテーションの重要な部分を設定するわけではなく、 'coordinate'プロパティです。そして、あなたは '' [super init] 'をある段階で呼び出さなければならないと思います。 –