gpt4 book ai didi

iOS7 - 在触摸屏幕之前不会出现 map View 图钉

转载 作者:行者123 更新时间:2023-11-28 22:15:28 27 4
gpt4 key购买 nike

在我的应用程序中,我使用 json 从 Web 服务下载一组点。将应用程序实现到 iOS7,我正在试验这个问题:位置已下载,但在用户触摸并“移动” map 之前不会绘制 map 上的图钉。然后它们出现并且都像在 iOS6 中一样工作。

我该如何纠正这种行为?

编辑:AddAnnotation 在接收数据的方法末尾调用,解析 json 并将它们传递给 mylocaction 对象:

- (void)plotBarPosition:(NSString *)data_string {
// Parse the string into JSON
NSDictionary *json = [(NSDictionary*)[datos_string1 JSONValue]objectForKey:@"features"];

for (int i = 0; i < [json count]; i++){

/*
PARSING EACH POINT
*/

MyLocation *location =[[MyLocation alloc] initWithName:nameLoc coordinate:coordinate estado:status antenaId:antenaId];

[_mapView addAnnotation:location];
}

}

我也试过:

[_mapView performSelectorOnMainThread: @selector(addAnnotations:) withObject: location waitUntilDone: NO];

但在这种情况下,注释根本不会出现。

最佳答案

作为this answer并且@RAJA 的评论建议,在主线程 上调用addAnnotation:addAnnotations:。您可以使用 GCD 或 performSelectorOnMainThread 执行此操作。

对现有代码更改最少的选项是调用 addAnnotation:(单数):

- (void)plotBarPosition:(NSString *)data_string {
// Parse the string into JSON
NSDictionary *json = [(NSDictionary*)[datos_string1 JSONValue]objectForKey:@"features"];

for (int i = 0; i < [json count]; i++){

/*
PARSING EACH POINT
*/

MyLocation *location =[[MyLocation alloc] initWithName:nameLoc coordinate:coordinate estado:status antenaId:antenaId];

//[_mapView addAnnotation:location];
[_mapView performSelectorOnMainThread:@selector(addAnnotation:)
withObject:location
waitUntilDone:YES];
}
}


或者,要使用 addAnnotations:(复数),您首先将注释添加到本地数组,然后在单个 调用中将它们一起提供给 map View 。下面的更改用 >>> 标记:

- (void)plotBarPosition:(NSString *)data_string {
// Parse the string into JSON
NSDictionary *json = [(NSDictionary*)[datos_string1 JSONValue]objectForKey:@"features"];

//>>> initialize array to hold annotations...
NSMutableArray *annotationsToAdd = [NSMutableArray array];

for (int i = 0; i < [json count]; i++){

/*
PARSING EACH POINT
*/

MyLocation *location =[[MyLocation alloc] initWithName:nameLoc coordinate:coordinate estado:status antenaId:antenaId];

//>>> comment out direct addAnnotation...
//[_mapView addAnnotation:location];

//>>> add annotation to local array...
[annotationsToAdd addObject:location];
}

//>>> call addAnnotations: (plural) on main thread...
[_mapView performSelectorOnMainThread:@selector(addAnnotations:)
withObject:annotationsToAdd
waitUntilDone:YES];
}

关于iOS7 - 在触摸屏幕之前不会出现 map View 图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21841225/

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