0

I'm looking for a solution to display a view when I select a mkannotation in my map. In the image:

enter image description here

If you selected a mkannotation, it is displayed the view that in the bottom. I have a way but I don't know if it's the best. It's just display the view under the map, like subview of the general view, but the problem I see it's that it was above the map, hiding a part of this, and I don't know how to detect that the user click on the map to hide the view of the profile.

Thanks in advance

Edit 1. With this code, I get errors, and if I fix it add .view to the errors, these disappear, but then when I select a mkannotation it doesn't appear nothing.

enter image description here

Juanjo
  • 929
  • 1
  • 15
  • 29
  • check these links [1](http://stackoverflow.com/questions/1275731/iphone-detecting-tap-in-mkmapview)[2](http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects) – Pawan Rai May 19 '14 at 15:32

1 Answers1

1

first time create i YourViewController.xib and in your mapviewcontroller use this code :

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    if(![view.annotation isKindOfClass:[MKUserLocation class]]) {
        YourViewController *calloutView = (YourViewController *)[[[NSBundle mainBundle] loadNibNamed:@"YourViewController" owner:self options:nil] objectAtIndex:0];
        CGRect calloutViewFrame = calloutView.frame;
        calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
        calloutView.frame = calloutViewFrame;

        [calloutView.calloutLabel setText:[(locationAnnotation*)[view annotation] title]];
        [calloutView.CallDattabel setText:[(locationAnnotation*)[view annotation] subtitle]];
        [calloutView.status setText:[(locationAnnotation*)[view annotation] status]];
        [calloutView.ImageSate setImage:[(locationAnnotation*)[view annotation] image ]];
        [view addSubview:calloutView];
    }

}
-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
    for (UIView *subview in view.subviews ){
        [subview removeFromSuperview];
    }
}

i hope this code is useful for you

said
  • 553
  • 5
  • 12
  • what do I need before? create a uiviewcontroller with its .xib? Because I cant get working that code – Juanjo May 19 '14 at 16:02
  • create new file cmd+n and chose Objective-c class ViewController and subclass of UIViewController and check also create XIB file – said May 19 '14 at 16:09
  • in your Pruebalpreviewcontroller use in fichier.h : @interface Pruebalpreviewcontroller : UIView – said May 20 '14 at 09:43
  • @Juanjo and in fichier.m use : - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } – said May 20 '14 at 09:44
  • @Juanjo and in your Pruebalpreviewcontroller.xib chos in simulated Matrics size freeform and status bar none – said May 20 '14 at 09:46
  • I did it and nothing, I get a black screen when I click a MKAnnotation – Juanjo May 20 '14 at 10:02
  • @Juanjo so custom your fichier.XIB with UILabel and send your data in UIlabel ok for exemple [calloutView.calloutLabel setText:@"your name here"]; – said May 20 '14 at 10:06
  • I did it, I have my custom .xib with white blackgroundColor and a label, but nothing. Don't you have a sample project or extended tutorial? – Juanjo May 20 '14 at 10:21
  • look for this exemple http://www.codigator.com/tutorials/advanced-mapkit-tutorial-for-ios-custom-callout/ – said May 20 '14 at 10:26