私が扱っている奇妙な問題があります... 私は mainviewcontrollers ビューにドラッグした非常に基本的な mkmapview を持っています。地図上に表示している非常に基本的な注釈があります。mainviewcontroller を mapview のデリゲート (IB またはコード内) にすると、注釈が表示されなくなります。この接続を行わないと、注釈は期待どおりに表示されます...何かアイデアはありますか?
#import "GDFlipsideViewController.h"
#import <MapKit/MapKit.h>
@interface GDMainViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet UIToolbar *bottomToolbar;
@property (strong, nonatomic) IBOutlet MKMapView *theMap;
@property (strong, nonatomic) MKLocalSearchResponse *results;
@property (strong, nonatomic) MKLocalSearchRequest *request;
@property (strong, nonatomic) MKLocalSearch *search;
- (IBAction)locateHelp:(UIBarButtonItem *)sender;
@end
...
@implementation GDMainViewController
...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
static NSString *AnnotationViewID = @"annotationViewID";
GDHelpAnnotationView *annotationView = (GDHelpAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil){
annotationView = [[GDHelpAnnotationView alloc]init];
}
annotationView.annotation = annotation;
return annotationView;
}
...
- (IBAction)locateHelp:(UIBarButtonItem *)sender {
[self searchForHelp];
}
..
- (void)searchForHelp {
// drop pins for emergency destination
[self searchForFireStations];
[self searchForPoliceStations];
[self searchForHospitals];
}
...
- (void)searchForFireStations {
//Fire stations
[_request setNaturalLanguageQuery:@"fire station"];
[_request setRegion:[_theMap region]];
_search = [[MKLocalSearch alloc]initWithRequest:_request];
[_search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
if ([response.mapItems count] == 0) {
if ([response.mapItems count] == 0) {
//will handle later
return;
}
}
[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop) {
GDHelpAnnotation *annotation = [[GDHelpAnnotation alloc] initWithPlacemark:item.placemark];
annotation.title = item.name;
annotation.subtitle = [item name];
[_theMap addAnnotation:annotation]; // This gets called but doesnt show annotations when self is _theMap's delegate
}];
}];
}