RightCalloutAccessoryView on MKMapView not showing

I have few problems with my iphone application. I have such classes and interfaces:

CinemaMapAnnotation.h

#import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface CinemaMapAnnotation : NSObject <MKAnnotation>{ CLLocationCoordinate2D coordinate; NSString *title; NSString *subtitle; } @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @property (nonatomic, copy) NSString* title; @property (nonatomic, copy) NSString* subtitle; -(id)initWithCoordinate:(CLLocationCoordinate2D) c; @end 

CinemaMapAnnotation.m

 #import "CinemaMapAnnotation.h" @implementation CinemaMapAnnotation @synthesize title, subtitle, coordinate; -(id)initWithCoordinate:(CLLocationCoordinate2D) c{ self = [super init]; if (self) { coordinate = c; } return self; } -(void) dealloc { self.title = nil; self.subtitle = nil; [super dealloc]; } @end 

CinemasMapController.h

 #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import "Cinema.h" #import "CinemaMapAnnotation.h" #import "PopcornuaAppDelegate.h" @interface CinemasMapController : UIViewController <MKMapViewDelegate, MKReverseGeocoderDelegate> { MKMapView *mapView; MKReverseGeocoder *reverseGeokoder; } @property (nonatomic, retain) IBOutlet MKMapView *mapView; @property (nonatomic, retain) IBOutlet MKReverseGeocoder *reverseGeokoder; @end 

CinemasMapController.m

 #import "CinemasMapController.h" @implementation CinemasMapController @synthesize mapView, reverseGeokoder; ... #pragma mark - Map Anotation - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id)annotation { static NSString* MyIdentifier = @"CinemaMapAnotation"; MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:MyIdentifier]; if (!pinView) { MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MyIdentifier] autorelease]; pinView.draggable = NO; pinView.animatesDrop = NO; pinView.enabled = YES; } else { pinView.annotation = annotation; } if(annotation != mapView.userLocation){ pinView.pinColor = MKPinAnnotationColorRed; pinView.canShowCallout = YES; // Add a detail disclosure button to the callout. pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; pinView.userInteractionEnabled = YES; } else { pinView.pinColor = MKPinAnnotationColorGreen; } return pinView; } - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { NSLog(@"Not show button, so not work"); } ... @end 

My problem is that everything shows and works, except that the rightCalloutAccessoryView button is not displayed. mapView is connected and has delegete for the CinemasMapController on the iphone screen (I will also try [mapView setDelegate: self]). So what am I doing wrong?

PS Code with line

 pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

run - verified by NSLog.

Here's what it looks like - there is no button: How its look like - no button

+4
source share
1 answer

In viewForAnnotation in the if (!pinView) , a new local pinView variable is pinView instead of being assigned to an external variable.

As a result, the pinView external variable pinView never set (remains nil ), and therefore the map view creates the default annotation view that you see.

+10
source

Source: https://habr.com/ru/post/1379024/


All Articles