Objective c MKPinAnnotationView可拖动无法工作。DragTable=是,callout具有标题和副标题,并且实现了setCoordinate

Objective c MKPinAnnotationView可拖动无法工作。DragTable=是,callout具有标题和副标题,并且实现了setCoordinate,objective-c,iphone,ios6,mapkit,Objective C,Iphone,Ios6,Mapkit,当我尝试拖动销时,它不会移动。当我触摸它时,它变暗了。然而,它从不抬起,也从不四处移动 以下是my annotation类的头文件: #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <Parse/Parse.h> @interface GeoPointAnnotation : NSObject <MKAnnotation> - (id)initWithObject:(PFObj

当我尝试拖动销时,它不会移动。当我触摸它时,它变暗了。然而,它从不抬起,也从不四处移动

以下是my annotation类的头文件:

#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
#导入
#进口
#进口
@接口地理点批注:NSObject
-(id)initWithObject:(PFObject*)对象;
@属性(非原子、读写、赋值)CLLocationCoordinate2D坐标;
@属性(非原子、只读、副本)NSString*标题;
@属性(非原子、只读、复制)NSString*副标题;
-(void)设置坐标:(CLLocationCoordinate2D)新坐标;
@结束
以下是我在视图控制器中创建注释的位置:

- (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;
}
-(无效)更新映射
{
[self.mapView removeAnnotations:self.mapView.annotations];
PFGeoPoint*geoPoint=[self.post location];
//将地图围绕地质点居中
[self.mapView setRegion:mkCoordinatereRegionMake(
CLLocationCoordination2DMAKE(地理点.纬度,地理点.经度),
MKCoordinateSpanMake(0.01,0.01)
)];
GeoPointAnnotation*annotation=[[GeoPointAnnotation alloc]initWithObject:self.post.object];
[self.mapView addAnnotation:annotation];
}
//通过解析从地理位置
#pragma标记-MKMapViewDelegate
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
静态NSString*GeoPointAnnotationIdentifier=@“RedPin”;
MKPinAnnotationView*annotationView=(MKPinAnnotationView*)[mapView出列重用AnnotationViewWithIdentifier:GeoPointAnnotationIdentifier];
如果(!annotationView){
annotationView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:地理点AnnotationIdentifier];
annotationView.pinColor=MKPinAnnotationColorRed;
annotationView.canShowCallout=是;
annotationView.draggable=是;
annotationView.animatesDrop=YES;
}
返回注释视图;
}

有什么想法吗?

发现了问题:我忘了在我的故事板xib中连接地图视图的代理。h/t Nitin Gohel-谢谢

我也来看看这个!你并不孤单。你应该接受你的帖子作为回答。