2014-04-11 4 views
3

iOS7.1이 출시 된 이후지도에서 사용자가지도를 탭하면지도에서 새로운 주석을 선택하는 데 코드에 문제가 계속 발생합니다. 이 코드는 iOS6 및 7에서 작동하지만 7.1에서는 엉망입니다.iOS7.1 MKMapView selectAnnotation 문제

이 문제에 대한 특정 정보를 찾지 못했지만 여기에 문제를 설명하기위한 매우 간단한 코드가 있습니다.

내 헤더는이 포함되어 다음과 같은

#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을 추가했다. 문제에 대한 아이디어를 공유해 주셔서 감사합니다.

문제는 주석을 선택하고 한 번에 선택을 해제하고 사용자가 제목을 다시 표시해야합니다.

답변

2

두 달 전에이 질문을 받았지만 현재 동일한 문제에 직면하고 있음을 알고 있습니다.

현재 mapView에 추가 한 후 작은 지연으로 주석을 선택하는 해결 방법을 사용하고 있습니다. 이것은 지연이 0.4 초 이상인 경우에 효과가있는 것으로 보인다. 그러나 지연이 < 0.4s 인 경우 선택 직후에 선택이 해제됩니다. 아주 이상한 :

//In the onClick handler 
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
annotation.coordinate = tapCoord; 
self.lastAnnotation = annotation; 
[self.mapView addAnnotation:annotation]; 
[self performSelector:@selector(selectLastAnnotation) withObject:nil afterDelay:0.4]; 

및 도우미 방법 :

-(void)selectLastAnnotation{ 
    [self.mapView selectAnnotation:self.lastAnnotation animated:YES]; 
} 
+0

덕분에, 지금이 권리를하고 있어요. 솔루션보다 신속한 해결 방법이므로 답변을 수락하지 않지만 여전히 도움이됩니다. – user2700551