以下是假设运行NSMutableArray
的*Students
与address
属性。但由于某些原因,for不是遍历整个NSMutableArray
,只是第一个对象。for(id obj in studentArray)只遍历数组中的第一项
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
for (id obj in studentArray) {
if ([obj isKindOfClass:[Student class]]) {
Student *selectedStudent = obj;
[geocoder geocodeAddressString:selectedStudent.address completionHandler:^(NSArray* placemarks, NSError* error){
for (CLPlacemark* aPlacemark in placemarks)
{
NSString *latDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.latitude];
NSString *lngDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.longitude];
NSLog(@"%@, %@",latDest1, lngDest1);
}
}];
}
}
任何想法我可能做错了什么?该应用程序不会崩溃,只是简单地检查数组中的4名学生中的一名。 谢谢
在调试器中使用断点和步进显示了什么? – CRD
@CRD该应用程序不会崩溃,只是在日志中输出1组坐标而不是4(数组中有4个学生) – Manesh
在上述代码的开始处放置一个断点,当调试器停止检查时变量值然后逐步通过。您可能还想在该块中添加一个断点,但无法进入该块。无论什么问题都可能会显而易见。 – CRD