0

当我尝试拖动图钉时,它不会移动。当我触摸它时,它会变暗。但是,它永远不会抬起,也永远不会移动。

这是我的注释类的头文件:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <Parse/Parse.h>

@interface GeoPointAnnotation : NSObject <MKAnnotation>

- (id)initWithObject:(PFObject *)aObject;

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;

- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;

@end

这是我在视图控制器中创建注释的地方:

- (void)updateMap
{
    [self.mapView removeAnnotations:self.mapView.annotations];

    PFGeoPoint *geoPoint = [self.post location];

    // center the map around the geopoint
    [self.mapView setRegion:MKCoordinateRegionMake(
       CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude),
       MKCoordinateSpanMake(0.01, 0.01)
       )];

    GeoPointAnnotation *annotation = [[GeoPointAnnotation alloc] initWithObject:self.post.object];
    [self.mapView addAnnotation:annotation];
}

// from Geolocations by Parse
#pragma mark - MKMapViewDelegate

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    static NSString *GeoPointAnnotationIdentifier = @"RedPin";

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:GeoPointAnnotationIdentifier];

    if (!annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:GeoPointAnnotationIdentifier];
        annotationView.pinColor = MKPinAnnotationColorRed;
        annotationView.canShowCallout = YES;
        annotationView.draggable = YES;
        annotationView.animatesDrop = YES;
    }

    return annotationView;
}

有任何想法吗?

4

1 回答 1

1

Found the problem: I forgot to hook up the Map View's delegate in my Storyboard xib. h/t Nitin Gohel - thanks!

于 2013-03-15T18:36:05.190 回答