调用MKMapViewDelegate但是Pin没有像我设置的那样掉线

时间:2013-04-02 10:01:10

标签: ios mkmapview mapkit mkpinannotationview mkmapviewdelegate

我尝试在MapView中删除一个引脚注释。但事实并非如此。

视图控制器有一个表视图,我将mapView插入标题。

DetailViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
 self.title = @"Nearby";

  //coord is CLLocationCoordinate2D which is instance variable 

 ItemMapPoint *itemMapPoint = [[SquakItemMapPoint alloc] initWithCoordinate:coord title:@"Test"];
[mapView addAnnotation:itemMapPoint];


MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 500, 500);
[mapView setRegion:region animated:YES];
//the delegate is not set here but I set it in Interface Builder

self.tableView.tableHeaderView = mapView;

}
/this is delegate method to set Pin to drop 
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id     <MKAnnotation>)annotation
{
  MKPinAnnotationView *annoView = [[MKPinAnnotationView alloc]
 initWithAnnotation:annotation
 reuseIdentifier:@"current"];  


annoView.animatesDrop = YES;
annoView.pinColor = MKPinAnnotationColorGreen;
return annoView;
}

当我在委托中设置时,引脚为绿色但在屏幕加载时引脚不会掉落。我试图将代码更改为ViewDidAppear(),但它仍然无效。

请帮忙。

先谢谢

1 个答案:

答案 0 :(得分:0)

两件事 -

  1. 确保您的ItemMapPointSquakItemMapPoint实施所需的协议。

  2. 尝试在添加注释mapView之前添加self.tableView.tableHeaderView = mapView;[mapView addAnnotation:itemMapPoint];