我有一个包含三个元素的数组的plist,所有这些都是字典。这些字典每个包含四项(纬度,经度,标题,副标题)。我想遍历每个元素并获取纬度和经度(这两者都是字典的属性)。通过包含字典数组的plist循环
使用以下代码。
- (void)loadAnnotations{
//retrieve path of plist file and populate relevant types with its information
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Places1" ofType:@"plist"];
branchList = [[NSArray alloc] initWithContentsOfFile:plistPath];
NSLog(@"hi inside method",branchList.lastObject);
self.branchList =[NSMutableArray array];
//code ok until this
for (NSDictionary *key in branchList)
{ NSLog(@"hi in loop");
PlaceFinderAnnotation *placeAnnotations = [[PlaceFinderAnnotation alloc] init];
//loop through annotations array, creating parking annotations filled with the information found in the plist
CLLocationDegrees latitude = [[key valueForKey:@"latitude"]floatValue];
CLLocationDegrees longitude = [[key valueForKey:@"longitude"]floatValue];
placeAnnotations.coordinate = CLLocationCoordinate2DMake(latitude, longitude);
[self.branchList addObject:placeAnnotations];
[placeAnnotations release]; placeAnnotations= nil;
objectForKey:@"subtitle"]];
}
}
问题是它没有进入循环。这意味着它不会打印出log命令“hi looppp”。
如果这是你的整个代码,那肯定是坏了。如果这不是你的整个代码,那么你不会因为遗漏部分而对自己有利。 –