поэтому с тех пор, как вышла iOS7.1, у меня продолжают возникать проблемы с моим кодом для выбора новых аннотаций на карте, когда пользователи нажимают на карту. Код работает с iOS6 и 7, но не работает с 7.1.
Я не нашел никакой конкретной информации по этой проблеме, но вот мой очень простой код, иллюстрирующий проблему.
Мой заголовок содержит только это:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MAViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mMapView;
@end
И мой файл реализации выглядит следующим образом:
#import "MAViewController.h"
@interface MAViewController ()
@end
@implementation MAViewController
@synthesize mMapView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.mMapView setDelegate:self];
[self.mMapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapTapped:)]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)mapTapped:(UITapGestureRecognizer *)recognizer
{
CGPoint touchPoint = [recognizer locationInView:self.mMapView];
CLLocationCoordinate2D touchMapCoordinate = [self.mMapView convertPoint:touchPoint toCoordinateFromView:self.mMapView];
CLLocation *lTapLocation = [[CLLocation alloc] initWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];
[self.mMapView removeAnnotations:mMapView.annotations];
MKPointAnnotation *lAnnotation = [[MKPointAnnotation alloc] init];
lAnnotation.coordinate = lTapLocation.coordinate;
lAnnotation.title = @"TAP";
[self.mMapView addAnnotation:lAnnotation];
}
#pragma mark - MapView Delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if([annotation isKindOfClass: [MKUserLocation class]]) {
return nil;
}
MKPinAnnotationView *lPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
lPin.canShowCallout = FALSE;
return lPin;
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *lAnnotationView = (MKAnnotationView*)[views objectAtIndex:0];
lAnnotationView.canShowCallout = YES;
if ([lAnnotationView.annotation isKindOfClass:[MKUserLocation class]]) {
return;
}
[mapView selectAnnotation:lAnnotationView.annotation animated:YES];
}
@end
Я просто добавил MKMapView в раскадровку, не более того. Спасибо, что поделились своими идеями по проблеме.
Проблема в том, что аннотация выбирается и отменяется одновременно, и пользователю нужно снова нажать на нее, чтобы отобразить заголовок.