Ios 循环应该运行4次,但只运行一次
我正在做一个基于地理定位的应用程序。这是我的密码:Ios 循环应该运行4次,但只运行一次,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我正在做一个基于地理定位的应用程序。这是我的密码: -(void)gettingDataSQL { NSURL *url = [NSURL URLWithString:@"http://www.xxx.fr/xxx/xxx/script_xxx_localisation.php"]; NSData *data = [NSData dataWithContentsOfURL:url]; if (data != nil) { jsonArray =
-(void)gettingDataSQL {
NSURL *url = [NSURL URLWithString:@"http://www.xxx.fr/xxx/xxx/script_xxx_localisation.php"];
NSData *data = [NSData dataWithContentsOfURL:url];
if (data != nil)
{
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"jSonArrayCount = %i", [jsonArray count]);
for (int i = 0; i<jsonArray.count; i++) {
NSString *address = [[jsonArray objectAtIndex:i] objectForKey:@"adresse"];
NSLog(@"address FROM JSON = %@", address);
NSString *titre = [[jsonArray objectAtIndex:i] objectForKey:@"titre"];
NSString *stringId = [[jsonArray objectAtIndex:i] objectForKey:@"id"];
[geocoder geocodeAddressString:address completionHandler:^(NSArray* placemarks, NSError* error){
// Check for returned placemarks
if (placemarks && placemarks.count > 0) {
NSLog(@"if placemarks && placemarks.count");
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]initWithPlacemark:topResult];
// [self.mapViewOutlet addAnnotation:placemark];
NSLog(@"Placemark posé au longitude : %f et latitude : %f", placemark.location.coordinate.longitude, placemark.location.coordinate.latitude);
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = placemark.location.coordinate;
annotation.title = titre;
annotation.subtitle = stringId;
[mapViewOutlet addAnnotation:annotation];
}
}];
NSLog(@"one placemark well defined via retrieveData:");
}
}
}
我想在地图上创建多个注释视图,而不仅仅是一个。我在数据库中下载了多个条目,以便在JsonArray的循环中显示在地图上,但地理编码后的代码只调用一次,因此它只显示我数据库的第一个条目
有什么想法吗,伙计们
提前感谢您的帮助和阅读;)
我希望它也能帮助其他有同样问题的人
回答之后
JSON数组的日志:
2014-09-15 21:24:21.544 xxxx[1416:60b] (
{
adresse = "115 rue de reuilly";
cree = "2014-07-13 21:03:23";
description = "Venez boire!";
icone = "icone_base.png";
id = 1;
"id_annonceur" = 1;
"id_type" = 3;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "La premiere Leffe gratuite!";
validite = "";
vues = 0;
},
{
adresse = "107 rue de reuilly";
cree = "2014-07-13 22:21:24";
description = "Le Match n'est pas fini, profitez-en !";
icone = "icone_base.png";
id = 2;
"id_annonceur" = 1;
"id_type" = 3;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "Karhu a -50%";
validite = "";
vues = 0;
},
{
adresse = "Metropole de la Gare";
cree = "2014-07-19 15:57:51";
description = "Premier arrive, premier servi!";
icone = "icone_base.png";
id = 4;
"id_annonceur" = 1;
"id_type" = 1;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "Le Mojito est gratuit!";
validite = "";
vues = 0;
},
{
adresse = "2 rue de reuilly";
cree = "2014-07-19 15:59:12";
description = "Depechez-vous !";
icone = "icone_base.png";
id = 5;
"id_annonceur" = 1;
"id_type" = 1;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "La dose du Martini doublee pour 1h!";
validite = "";
vues = 0;
}
启动前向地理编码请求后,不要尝试启动另一个前向或反向地理编码请求
-引用苹果的文档
:请显示
jsonArray的日志打印
对于我们愚蠢的美国人,定义“boucle”。(或者更好的是,使用一个英语术语。)@HotLicks-boucle-loop。小错误。@rptwsthi请参见编辑。非常感谢你的回答!通过以下帮助,问题得以解决:感谢您的回答。那么,我如何解决在地图上放置许多不同注释的问题呢?
2014-09-15 21:24:21.544 xxxx[1416:60b] (
{
adresse = "115 rue de reuilly";
cree = "2014-07-13 21:03:23";
description = "Venez boire!";
icone = "icone_base.png";
id = 1;
"id_annonceur" = 1;
"id_type" = 3;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "La premiere Leffe gratuite!";
validite = "";
vues = 0;
},
{
adresse = "107 rue de reuilly";
cree = "2014-07-13 22:21:24";
description = "Le Match n'est pas fini, profitez-en !";
icone = "icone_base.png";
id = 2;
"id_annonceur" = 1;
"id_type" = 3;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "Karhu a -50%";
validite = "";
vues = 0;
},
{
adresse = "Metropole de la Gare";
cree = "2014-07-19 15:57:51";
description = "Premier arrive, premier servi!";
icone = "icone_base.png";
id = 4;
"id_annonceur" = 1;
"id_type" = 1;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "Le Mojito est gratuit!";
validite = "";
vues = 0;
},
{
adresse = "2 rue de reuilly";
cree = "2014-07-19 15:59:12";
description = "Depechez-vous !";
icone = "icone_base.png";
id = 5;
"id_annonceur" = 1;
"id_type" = 1;
lat = "";
lon = "";
note = 0;
portee = 25;
titre = "La dose du Martini doublee pour 1h!";
validite = "";
vues = 0;
}