iOS7 - 触摸屏幕前不会显示地图视图引脚 [英] iOS7 - Map view pin do not appear until screen is touched

查看:102
本文介绍了iOS7 - 触摸屏幕前不会显示地图视图引脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my app, I download a set of point from a web service using json. Actualizing the app to iOS7, I am experimenting that problem: the locations are downloaded but pins on the map are not painted until user touchs and "moves" the map. Then they appear and all work as in iOS6.

如何纠正这种行为?

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

AddAnnotation is called at the end of a method that receive data, parse the json and pass them to mylocaction object:

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

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

but in this case, annotations do not appear at all.

推荐答案

作为此答案和评论通过@RAJA建议,在主线程上调用 addAnnotation: addAnnotations:。您可以使用GCD或 performSelectorOnMainThread 执行此操作。

As this answer and the comment by @RAJA suggest, call addAnnotation: or addAnnotations: on the main thread. You could do this using GCD or performSelectorOnMainThread.

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

The option with the least changes to your existing code is to call addAnnotation: (singular):

- (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:(复数),首先将注释添加到本地数组,然后在单个调用中将它们一起提供给地图视图。以下更改标有>>>


Alternatively, to use addAnnotations: (plural), you first add your annotations to a local array and give them to the map view all together in a single call. Changes below are marked with >>>:

- (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 - 触摸屏幕前不会显示地图视图引脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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