我在完成这项工作时遇到问题,我使用核心数据来获取用户列表,
NSFetchrequets 额外的用户位置,地点列表和邮政编码
NSFetchRequest *request =[NSFetchRequest fetchRequestWithEntityName:@"SiteLocation"]; //request all objects
NSArray *fetchedObjects = [self.srmDatabase.managedObjectContext executeFetchRequest:request error:nil];
所以我有一个实体“SiteLocation”用 FetchedResultController 加载 tableview
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"CELL");
static NSString *CellIdentifier = @"Site Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
SiteLocation * siteLocation = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = siteLocation.siteName;
return cell;
}
然后我将选定的行发送到 MapViewController didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didselect sitePC");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UserDetails *userinfo = [[self fetchedResultsController] objectAtIndexPath:indexPath];
self.mapview.sitePC = userinfo; //sitePC is (id)
NSLog(@"object selected= %@", userinfo);
}
}
2012-10-04 13:27:46.401 SRMAB[459:c07] didselect sitePC = <SiteLocation: 0x1d80ad20> (entity: SiteLocation; id: 0x1d86b210 <x-coredata://523E1EB6-01DF-4889-B1A1-2E38E92D385E/SiteLocation/p120> ; data: {
projectName = (
"0x1d82bc20 <x-coredata://523E1EB6-01DF-4889-B1A1-2E38E92D385E/UserDetails/p144>"
);
siteName = "Bloomberg Place 1";
sitePostCode = "W1B 5AU";
})
在 MapViewController 上,这会将 sitePostcode 转换为 PlaceMark
-(void)myMapview
{
NSLog(@"mymapview");
NSString *addressString = [self.sitePC valueForKey:@"sitePostCode"];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)
{
NSLog(@"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark1 in placemarks)
{
NSLog(@"Placemark: %@",placemark1);
//[self displayPlacemarks:placemarks];
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = placemark1.location.coordinate.latitude;
zoomLocation.longitude= placemark1.location.coordinate.longitude;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1000, 1000);
MKCoordinateRegion adjustedRegion = [self.mapview regionThatFits:viewRegion];
[self.mapview setRegion:adjustedRegion animated:YES];
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = placemark1.location.coordinate;
pa.title = [self.sitePC valueForKey:@"siteName"];
[self.mapview addAnnotation:pa];
}
我希望这是有道理的。
加载时如何在地图上显示所有位置?
问题已更新,因为原始问题是拼写错误