MKAnnotation不是在iOS5中得到选择 [英] MKAnnotation not getting selected in iOS5

查看:159
本文介绍了MKAnnotation不是在iOS5中得到选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序放置在地图上的图钉,然后选择它的使用动画,使用户有一个视觉线索,可以立即读取标题/副标题。下面code工作在双方的iOS4 iOS5的和,但在iOS5中,注释不会被自动除非我在selectAnnotation方法更改动画为NO选择。

任何想法,为什么?

  MapAnnotations *图钉= [[MapAnnotations页头] initWithCoordinate:坐标];
pushpin.title = [selectedStation valueForKey:@名];
pushpin.subtitle = [selectedStation valueForKey:@地址];
[stationMap addAnnotation:图钉];
[stationMap selectAnnotation:图钉动画:是];[图钉发布]图钉=零;


解决方案

不知道为什么它会前工作,但动画可能要求创建其中添加注释后是不可能的注解视图,并准备好了。

你可以做的是移动选择到 didAddAnnotationViews 委托方法,它应该在所有iOS版本的工作:

   - (空)的MapView:(*的MKMapView)的MapView didAddAnnotationViews:(NSArray的*)的意见
{
    对于(MKAnnotationView *在意见AV){
        如果([av.annotation isKindOfClass:[MapAnnotations类]){
            MapAnnotations *图钉=(MapAnnotations *)av.annotation;
            如果(_this_pushpin_is_the_one_to_select){
                [图形页面selectAnnotation:av.annotation动画:YES];
                打破; //或返回;
            }
        }
    }
}

My app places a pushpin on the map and then selects its using animation so the user has a visual clue and can immediately read the title/subtitle. The following code works in both iOS4 and iOS5, but in iOS5, the annotation doesn't get selected automatically unless I change the animation to NO in the selectAnnotation method.

Any ideas why?

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;

解决方案

Not sure why it would work before but the animation probably requires the annotation view to be created and ready which is unlikely immediately after adding the annotation.

What you can do is move the selection to the didAddAnnotationViews delegate method which should work on all iOS versions:

- (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;
            }
        }
    }
}

这篇关于MKAnnotation不是在iOS5中得到选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆