gpt4 book ai didi

ios - MKPointAnnotation 副标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:13:22 28 4
gpt4 key购买 nike

我创建了很多图钉,当我按下图钉时,标题必须显示,而副标题必须隐藏,因为它是一段很长的文本并且出现在 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) 来保存您不想在标注上显示的数据。

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

在该示例中,将 @property (nonatomic, assign) float myValue; 替换为您要使用每个注释跟踪的数据(例如 @property (nonatomic, copy) NSString *键值;).

然后你会像这样创建你的注释:

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

annotationPoint2.title = [NSString stringWithFormat:@"%@", obj];
annotationPoint2.subtitle = @""; //or set to nil
annotationPoint2.keyValue = [NSString stringWithFormat:@"%@", key];

然后 didSelectAnnotationView 方法将如下所示:

- (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)。

关于ios - MKPointAnnotation 副标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12858218/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com