gpt4 book ai didi

ios - MKAnnotation 未在 iOS5 中被选中

转载 作者:可可西里 更新时间:2023-11-01 04:40:28 26 4
gpt4 key购买 nike

我的应用程序在 map 上放置了一个图钉,然后使用动画选择它,这样用户就有了视觉线索并可以立即阅读标题/副标题。以下代码适用于 iOS4 和 iOS5,但在 iOS5 中,除非我在 selectAnnotation 方法中将动画更改为 NO,否则不会自动选择注释。

有什么想法吗?

MapAnnotations *pushpin = [[MapAnnotations alloc] initWithCoordinate:coordinate];
pushpin.title = [selectedStation valueForKey:@"name"];
pushpin.subtitle = [selectedStation valueForKey:@"address"];
[stationMap addAnnotation:pushpin];
[stationMap selectAnnotation:pushpin animated:YES];

[pushpin release]; pushpin = nil;

最佳答案

不确定为什么它以前会起作用,但动画可能需要创建并准备好注释 View ,这不太可能在添加注释后立即进行。

您可以将选择移动到 didAddAnnotationViews 委托(delegate)方法,该方法应该适用于所有 iOS 版本:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView *av in views) {
if ([av.annotation isKindOfClass:[MapAnnotations class]]) {
MapAnnotations *pushpin = (MapAnnotations *)av.annotation;
if (_this_pushpin_is_the_one_to_select) {
[mapView selectAnnotation:av.annotation animated:YES];
break; //or return;
}
}
}
}

关于ios - MKAnnotation 未在 iOS5 中被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884379/

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