0

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'
  • If you're trying to access the annotation in the prepareForSegue method, see http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked for one way to do it. –  Jan 28 '14 at 02:42
  • Thanks Anna, I have seen several of your answers and they are always very thorough. I am not using JSON and have tried the method described in the post you mentioned to no prevail. I need to make my app self contained to be able tu use it abroad without having "roaming data" on and therefore no access to the web. I imported the pictures directly in the app. I believe my problem is that I cannot find a way to link a picture to an annotation (like I would do in a tableview). Creating a dictionary seems like the logical approach but how would I link a pict to an ann? – user3242404 Feb 02 '14 at 00:24
  • Thank you but... I don't understand what web availability has to do with your question. Even with your comment, I still don't understand what specific problem you're having. Your annotation class already has a link to an image (UIImage). What's the problem? Maybe you should store just the name (NSString) of the image in the class and then it would be more flexible. Update your question and try to give a better description of the problem. Include the _specific_ error or problem that happens. –  Feb 02 '14 at 02:48
  • Please look very carefully at Rob's answer. In the `calloutAccessoryControlTapped` method, it calls performSegue with `sender:view];` but you are doing `sender:self];` (`self` is the view controller but `view` in that method is the annotation view which is what you want). –  Feb 05 '14 at 17:01

0 Answers0