我有一個包含三個元素的數組的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」。
如果這是你的整個代碼,那肯定是壞了。如果這不是你的整個代碼,那麼你不會因爲遺漏部分而對自己有利。 –