【问题标题】:Why does selectAnnotation not work in this scenario?为什么 selectAnnotation 在这种情况下不起作用?
【发布时间】:2012-04-14 21:02:20
【问题描述】:

当我的地图视图出现以下代码时,我正在设置 MapView 注释,除了选择之外,这一切似乎都工作正常:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    MapAnnotation *pinpoint = [[MapAnnotation alloc] initWithTitle:@"Title" andCoordinate:loc];

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 1500, 1500);
    [self.mapView setRegion:region animated:true];
    [self.mapView addAnnotation:pinpoint];
    [self.mapView selectAnnotation:pinpoint animated:true];  //nothing happens!?   
}

但是如果在这个回调中调用相同的方法,它可以正常工作:

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    [mv selectAnnotation:mp animated:YES];
}

这是什么原因造成的?这不是调用 selectAnnotation 的合适位置吗?我是否必须等到调用 viewForAnnotation 之后?

【问题讨论】:

标签: ios mapkit


【解决方案1】:

必须先添加注释视图,然后才能选择注释。

请看这个热门问题:

How to trigger MKAnnotationView's callout view without touching the pin?

【讨论】:

    猜你喜欢
    • 2017-11-26
    • 2010-12-29
    • 1970-01-01
    • 2021-08-05
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多