I found out how to push titles and subtitles to DVcontroller but not pictures. I would like to push annotations specific pictures to a new DV when detail disclosure button is tapped. (using Xcode5)
I have the storyboard setup with 2 VC and the first one is embeded in a Nav Controller. The pins show on the map (NSMutable array) and the callout comes up with detail disclosure button on the right (and one on the left as well for future use). The segue from the detail disclosure button works as I can see a blue background screen on the DVcontroller upon tapping it. I have imported pictures files and associated them to each annotation.
I believe the answer is in the "calloutAccessoryControlTapped" method. I tried several codes in that method but still cannot return a picture in the DVcontroller.
ViewController.m is as follows:
(each annotation is set up like this):
//Chateau l'Evesque annotation
myAnn = [[myAnnotation alloc] init];
location.latitude = CLEVESQUE_LATITUDE;
location.longitude = CLEVESQUE_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"Château l'Evesque";
myAnn.imageView=[UIImage imageNamed:@"Château l'Evesque"];
[locations addObject:myAnn];
(then viewForAnnotation method):
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass: [MKUserLocation class]]) return nil;
static NSString *reuseId = @"myAnn";
MKAnnotationView *customAnnotationView = [mapView
dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (customAnnotationView == nil)
{
myAnnotation *myAnn = (myAnnotation *)annotation;
}
MKPinAnnotationView *Mypin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"current"];
Mypin.pinColor = MKPinAnnotationColorPurple;
UIButton *directionButton = [UIButton buttonWithType:UIButtonTypeCustom];
directionButton.frame = CGRectMake(0, 0, 23, 23);
[directionButton setBackgroundImage:[UIImage imageNamed:@"PetitVolant.png"]
forState:UIControlStateNormal];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
Mypin.leftCalloutAccessoryView = directionButton;
Mypin.rightCalloutAccessoryView = infoButton;
Mypin.draggable = NO;
Mypin.highlighted = YES;
Mypin.animatesDrop = TRUE;
Mypin.canShowCallout = YES;
return Mypin;
}
(then the culprit):
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
myAnnotation *myAnn = (myAnnotation *)view.annotation;
NSLog(@"myAnn.imageView = %@",myAnn.imageView);
[self performSegueWithIdentifier:@"ShowPhotoSegue" sender:self];
}
(I greened out the "prepareForSegue" method because it is not changing anything to the result so far.)
I rewrote the whole thing. Still the same problem. I am going to try to better explain the issue. I just want to push a picture (.png file) to the next view controller. I only get a blank (white) screen on the Detail VC after tapping the detail disclosure button.
If I include the following prepareForSegue
method (as described in the suggested post):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ToDetail"])
{
MKAnnotationView *annotationView = sender;
[segue.destinationViewController setAnnotation:annotationView.annotation];
I get the following error:
GuideDesVinsCPA[2523:70b] myAnn.imageForMyAnnotation = <UIImage: 0x9a4f510>
GuideDesVinsCPA[2523:70b] -[MapViewController annotation]: unrecognized selector sent to instance 0x9f31970
GuideDesVinsCPA[2523:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController annotation]: unrecognized selector sent to instance 0x9f31970'