accessing array from plist to show co ordinates in map view
I have a table view which goes down a few levels. On the last level is a table view with information(which is taken from a plist) about the item that was selected.
I want to click on one of the cells to launch a new view, Mapview to show the co ordinates which are stored in the plist.
I can add the view and get the basics of the map view working but I'm having trouble accessing the co ordinates which are stored in the plist.
I've looked for guidance on other websites开发者_StackOverflow社区 and they access the plist from the viewdidload in the mapviewcontroller and do objectforkey to get the co ordinates, but my coordinates are a few levels down in the plist and since i can't do indexforpath in viewdidload is there an alternative way of doing it?
The way I would do this, is when you select a row in a table view, select the objectAtIndexPath, and pass it to the next view (perhaps as an object called selectedItem)
then when you are in view did load, you could do something like this:
-(void)viewDidLoad{
...
CLLocationCoordinate2d coordinate=CLLocationCoordinate2dMake([[self.selectedItem latitude] doubleValue],[[self.selectedItem longitude] doubleValue]);
...
}
without seeing your plist structure, and also your ViewController Hierarchy, it is quite difficult to see if this approach would help.
edit: having looked at your xml file, you can drill into your plist like this:
NSArray *rows=[[NSDictionary dictionaryWithContentsOfURL:<url>] objectForKey:@"Rows"];
NSArray *children=[[rows objectAtIndex:< >] objectForKey:@"Children"];
NSDictionary *item=[children objectAtIndex:< >];
CLLocationCoordinate2d coordinate=CLLocationCoordinate2dMake([[item objectForKey:@"Latitude"] doubleValue],[[item objectForKey:@"Longitude"] doubleValue]);
精彩评论