【问题标题】:MKAnnotationView not displaying the titleMKAnnotationView 不显示标题
【发布时间】:2012-08-23 07:59:33
【问题描述】:

我正在使用以下代码为两个MKAnnotationView 设置标题:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation 
{

if(([annotation isKindOfClass:[Test_flag class]])) 
{

    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"PinId1";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin1"] autorelease];
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        [pinView setImage:[UIImage imageNamed:@"flg.png"]];
        [pinView setSelected:YES animated:YES];

    } 
    else 
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}
else if(([annotation isKindOfClass:[Distance1 class]])) 
{
    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"PinId4";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin4"] autorelease];

        pinView.canShowCallout = YES;
        [pinView setImage:[UIImage imageNamed:@"Circle_Grey.png"]];
        [pinView setSelected:YES animated:YES];

    } 
    else 
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

当我触摸地图时,MKAnnotationView 都被指向,但它们没有显示标题。是什么原因?请帮我找。

【问题讨论】:

标签: iphone xcode mkmapview mkannotationview callouts


【解决方案1】:

您错过了在Test_flag 类中编写title 方法。

【讨论】:

  • 我在 Test_flag 类中也添加了 NSString *title 和 @property,@synthesize
  • 向地图添加注记时,将值设置为标题。现在硬编码返回临时值来检查。
  • 我也喜欢 test_flag.title = @"Distance"; test_flag.subtitle = @"0.0";
  • 显示您在地图中添加注释的代码。
  • Test_flag *test_flag = [[Test_flag alloc] init]; test_flag.title = @"距离"; test_flag.subtitle = @"0.0"; [mapView addAnnotation:test_flag];之后设置坐标,如 test_flag.coordinate = CLLocationCoordinate2DMake(28.458586, 77.109126);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 2011-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多