I have a list of gyms with all its properties in Core Data, I get this gyms with an NSFetchRequest and pass its to a NSArray, then with a For in and this array, I get to put the pins in the MapView, I do it with de next code (welcome suggestions for improvement this):
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
NSFetchRequest *reqInst = [NSFetchRequest fetchRequestWithEntityName:[KMTInstalacion entityName]];
reqInst.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:KMTInstalacionAttributes.tipoInstalacion_ES ascending:NO]];
KMTAppDelegate *appDelegate = (KMTAppDelegate *)[[UIApplication sharedApplication]delegate];
NSError *error;
NSArray *arrayInstalaciones = [appDelegate.model.context executeFetchRequest:reqInst error:&error];
NSLog(@"Las instalaciones encontradas en arrayInstalaciones son: %lu", (unsigned long)[arrayInstalaciones count]);
for (KMTInstalacion *todasInstalaciones in arrayInstalaciones) {
CLLocationCoordinate2D coordPunto1 = CLLocationCoordinate2DMake(todasInstalaciones.coorLatitudValue, todasInstalaciones.coorLongitudValue);
MKPointAnnotation *anotacion = [[MKPointAnnotation alloc]init];
[anotacion setCoordinate:coordPunto1];
[anotacion setTitle:todasInstalaciones.nombre_ES];
[anotacion setSubtitle:todasInstalaciones.direccion_ES];
[self.mapView addAnnotation:anotacion];
}}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"curr"];
pinView.animatesDrop = NO;
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pinView;
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
KMTMiAnotacion *anotacion = view.annotation;
KMTDetailVC *detalle = [[KMTDetailVC allc]init];
detalle.title = anotacion.title
detalle.nombreInstalacionSeleccionada = anotacion.instalacion;
[self performSegueWithIdentifier:@"deMapa" sender:self];
}
KMTMiAnotacion.h
@interface KMTMiAnotacion : NSObject <MKAnnotation>{
NSString *title;
NSString *subTitle;
KMTInstalacion *instalacion;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subTitle;
@property (nonatomic, copy) KMTInstalacion *instalacion;
@end
When I tap on one of the pinView shows me the name and address of the gym with the button to the right.
Now what I want is when you tap on the pinView button, take you to the DetailView view and send full gym object (KMTInstalacion) corresponding pinView you've pressed, not just the title or subtitle, since each gym has about 50 properties (photos, schedules, etc ...)
Any idea how to do this?