Ios MKPointAnnotation字幕

Ios MKPointAnnotation字幕,ios,mapkit,mkannotation,Ios,Mapkit,Mkannotation,我已经创建了许多pin,当我按下pin时,标题必须显示,而字幕必须隐藏,因为它是一段很长的文本,并且显示在UItextView中。问题是我没有找到隐藏字幕的方法,所以在标题下,我有一段很长的文字,结尾是: - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { MKPointAnnotation *myAnnot = (MKPointAnnotation *)view.

我已经创建了许多pin,当我按下pin时,标题必须显示,而字幕必须隐藏,因为它是一段很长的文本,并且显示在UItextView中。问题是我没有找到隐藏字幕的方法,所以在标题下,我有一段很长的文字,结尾是:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    MKPointAnnotation *myAnnot = (MKPointAnnotation *)view.annotation;
    field.text = myAnnot.subtitle;
}
不幸的是,我不得不使用这个方法,因为我找不到一种方法将标记分配给MKPointAnnotation。我就是这样创建它的:

MKPointAnnotation *annotationPoint2 = [[MKPointAnnotation alloc] init];
annotationPoint2.coordinate = anyLocation;

annotationPoint2.title = [NSString stringWithFormat:@"%@", obj];
annotationPoint2.subtitle = [NSString stringWithFormat:@"%@", key];

不要使用内置的
MKPointAnnotation
类,而是创建一个自定义注释类,该类实现
MKAnnotation
,但具有一个附加属性(未命名为
subtitle
)来保存不希望在标注上显示的数据

包含一个简单的自定义注释类的示例

在该示例中,替换
@property(非原子,赋值)float myValue
中包含每个注释要跟踪的数据(例如,
@property(非原子,复制)NSString*keyValue;

然后,您将创建如下注释:

MyAnnotation *annotationPoint2 = [[MyAnnotation alloc] init];
annotationPoint2.coordinate = anyLocation;

annotationPoint2.title = [NSString stringWithFormat:@"%@", obj];
annotationPoint2.subtitle = @"";  //or set to nil
annotationPoint2.keyValue = [NSString stringWithFormat:@"%@", key];
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if ([view.annotation isKindOfClass:[MyAnnotation class]])
    {
        MyAnnotation *myAnnot = (MyAnnotation *)view.annotation;
        field.text = myAnnot.keyValue;
    }
    else
    {
        //handle other types of annotations (eg. MKUserLocation)...
    }
}
然后,
didSelectAnnotationView
方法如下所示:

MyAnnotation *annotationPoint2 = [[MyAnnotation alloc] init];
annotationPoint2.coordinate = anyLocation;

annotationPoint2.title = [NSString stringWithFormat:@"%@", obj];
annotationPoint2.subtitle = @"";  //or set to nil
annotationPoint2.keyValue = [NSString stringWithFormat:@"%@", key];
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if ([view.annotation isKindOfClass:[MyAnnotation class]])
    {
        MyAnnotation *myAnnot = (MyAnnotation *)view.annotation;
        field.text = myAnnot.keyValue;
    }
    else
    {
        //handle other types of annotations (eg. MKUserLocation)...
    }
}

您可能还必须更新代码的其他部分,这些部分假定注释是
MKPointAnnotation
,或者使用注释的
subtitle
(该代码应检查
MyAnnotation
并使用
keyValue
)。

您可以尝试这种简单的方法

MKPointAnnotation *point= [[MKPointAnnotation alloc] init];
point.coordinate= userLocation.coordinate;
point.title= @"Where am I?";
point.subtitle= @"u&me here!!!";
[myMapView addAnnotation:point];