0

我尝试制作一个 pin 注释以放入 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;
}

我在代理中设置的 Pin 是绿色的,但是当屏幕加载时 Pin 不会掉落。我也尝试将代码更改为 ViewDidAppear() 但它仍然不起作用。

请帮忙 。

提前致谢

4

1 回答 1

0

两件事情-

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

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

于 2013-04-02T10:13:48.457 回答