未找到MKAnnotation标题属性

时间:2016-12-01 13:42:16

标签: ios mkmapview core-location

未找到MKAnnotation标题属性

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
 {
   MKAnnotationView *selectedAnnotation = (MKAnnotationView *)view.annotation;//view.annotation; // This will give the annotation.
  NSString *temp = selectedAnnotation.title;
}

3 个答案:

答案 0 :(得分:0)

那是因为它没有标题https://developer.apple.com/reference/mapkit/mkannotationview

您希望获得视图为标题呈现的MKAnnotation

https://developer.apple.com/reference/mapkit/mkannotation

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
   MKAnnotation *selectedAnnotation = (MKAnnotation *)view.annotation;//view.annotation; // This will give the annotation.
  NSString *temp = selectedAnnotation.title;
}

答案 1 :(得分:0)

如果您设置多个引脚以将它们的标题映射到数组

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    NSUInteger index = [mapView.annotations indexOfObject:view.annotation];
    NSLog(@"index no %lu",(unsigned long)index);
    NSString *temp =__titlesArray[index];
}

答案 2 :(得分:0)

找到答案,

将视图控制器作为MyAnnotaionViewController

然后在委托方法中调用MyAnnotaionViewController

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
 MyAnnotaionViewController *selectedAnnotation =   (MyAnnotaionViewController *)view.annotation;//view.annotation; // This will give the annotation.
 NSString *temp = selectedAnnotation.title;
}