В вашем View Controller, в котором вы реализуете MapView, вы должны реализовывать метод делегата MapView, viewForAnnotation !!!
Реализуйте это так:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView * annotationView = nil;
[mapLoadingIndicatorView stopAnimating];
if ([annotation isKindOfClass:[MKUserLocation class]]) {
[self.mapView.userLocation setTitle:@"User1"];
return annotationView;
}
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentAnnotation"];
annotationView.canShowCallout = YES;
return annotationView;
}
А также убедитесь, что вы создали класс AddressAnnotation, в котором
AddressAnnotation.h
@interface AddressAnnotation : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString * title_;
NSString * subtitle_;
}
@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString * title_;
@property (nonatomic, retain) NSString * subtitle_;
@end
И AddressAnnotation.m:
@implementation AddressAnnotation
@synthesize coordinate, title_, subtitle_;
- (id)initWithCoordinate:(CLLocationCoordinate2D)c: (NSString *)title: (NSString *)subtitle {
if ((self = [super init])) {
coordinate= c ;
self.title_ = [NSString stringWithFormat:@"%@", title];
self.subtitle_ = [NSString stringWithFormat:@"%@", subtitle];
NSLog(@"title_%@", self.title_);
NSLog(@"subtitle_%@", self.subtitle_);
//self.title_ = @"Title";
//self.subtitle_ = @"Subtitle";
}
return self;
}
- (NSString *)title {
return self.title_;
}
- (NSString *)subtitle {
return self.subtitle_;
}
@end