【问题标题】:Update annotation's subtitle更新注解的副标题
【发布时间】:2013-05-09 08:40:50
【问题描述】:

点击后,我正在努力在 MapView 中设置注释的副标题。

.m:

MKCoordinateRegion England = { {0.0, 0.0} , {0.0, 0.0} };
England.center.latitude = 51.50063;
England.center.longitude = -0.124629;
England.span.longitudeDelta = 100.0f;
England.span.latitudeDelta = 100.0f;
[mapView setRegion:England animated:YES];

Annotation *ann1 = [[Annotation alloc] init];
ann1.title = @"England";
ann1.subtitle = @"subtitle";
ann1.coordinate = England.center;
[mapView addAnnotation:ann1];


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

MKPinAnnotationView *MyPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation  reuseIdentifier:@"current"]; MyPin.pinColor = MKPinAnnotationColorPurple;

UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[advertButton addTarget:self action:@selector(button:)  forControlEvents:UIControlEventTouchUpInside];


MyPin.rightCalloutAccessoryView = advertButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop = TRUE;
MyPin.canShowCallout = YES;

return MyPin;


}

- (void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)view
{
id<MKAnnotation> selectedAnn = [mapView.selectedAnnotations objectAtIndex:0];
country_title = selectedAnn.title;

selectedAnn.subtitle = @"NEW SUBTITLE";

}

点击注释后如何设置字幕?我不想那样做,因为我在点击 mysql 时会从 mysql 中获取一些行.. 但我不知道如何更新特定注释的字幕?

提前致谢! :)

【问题讨论】:

    标签: ios xcode annotations android-mapview


    【解决方案1】:
        id<MKAnnotation> selectedAnn = view.annotation;
    [mapview removeAnnotation:selectedAnn];
    
    .. Add Annotation with new subtitle
    
    [mapview addAnnotation:newselectedAnn];
    [newselectedAnn setSelected:Yes animated:No];
    

    希望对你有帮助

    【讨论】:

    • 嗨莫希特!感谢您的快速回复。不幸的是,我很困惑该放在哪里?我的 didSelectAnnotationView 中已经有了它: id selectedAnn = [mapView.selectedAnnotations objectAtIndex:0];... 我对此很陌生 :(
    • 用我的sn-p替换全部内容
    • 我试过你的 sn-p,但它只能让我把一个新的注释放在一个特定的地方。如果不是我点击的注释怎么办?你不能只设置一个 NSString 属性然后说: id selectedAnn = view.annotation; country_title = selectedAnn.title; if ([country_title isEqualToString:@"USA"]) { subtitle_USA = @"NEW SUBTITLE"; }
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多