MapKit How to pass managedObject from mapView to mapDetailView

若如初见. 提交于 2019-12-07 09:57:30

indexPath is undeclared because you're not implementing a UITableViewDataSource method in this case! I don't know what you're trying to accomplish here, but I think that there could be more than one possible solution. First, you could try to add an object property to your annotation, and use that to get the corresponding NSManagedObject from the annotation. Second, you could use an NSMutableDictionary to store the objects instead of an NSArray. You would use it as follows:

NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

for(NSManagedObject *object in markerObjects) {
  // Create the annotation
  MapLocation *annotation = [[MapLocation alloc] init];

  [dictionary setObject:object forKey:annotation]
}

Then you would retrieve the corresponding object for an annotation like this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
  NSManagedObject *object = [dictionary objectForKey:view.annotation];

  // Do whatever you want with your object
}

Please note that MapLocation here must conform to the NSCopying protocol since it is copied by the setObject:forKey: method.

Third, you could add all the informations (address, city, state, etc.) to your NSManagedObject subclass that conforms to the MKAnnotation protocol, and you won't have anymore the problem of retreiving an annotation corresponding to an object, since that would be the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!