我已经创建了许多引脚,当我按下引脚时,标题必须显示,而副标题必须隐藏,因为它是一段很长的文本,并且它出现在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];发布于 2012-10-12 20:33:02
不使用内置的MKPointAnnotation类,而是创建一个实现MKAnnotation的自定义注释类,但使用一个额外的属性(不是命名为subtitle)来保存您不希望在标注中显示的数据。
This answer包含一个简单的自定义注释类的示例。
在该示例中,将@property (nonatomic, assign) float myValue;替换为要使用每个批注跟踪的数据(例如,@property (nonatomic, copy) 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];然后,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)。
发布于 2015-08-31 17:57:14
你可以试试这个简单的方法,
MKPointAnnotation *point= [[MKPointAnnotation alloc] init];
point.coordinate= userLocation.coordinate;
point.title= @"Where am I?";
point.subtitle= @"u&me here!!!";
[myMapView addAnnotation:point];https://stackoverflow.com/questions/12858218
复制相似问题