2013-02-23 1 views
0

MKMapViewDelegate을 구현하는 클래스를 하위 클래스로 지정합니다. 수퍼 클래스에서 위임자도 설정하고 있지만 -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 메서드는 호출되지 않습니다. 여기 내 코드는하지만MKMapViewDelegate를 구현하는 클래스를 상속 받지만 MKMapViewDelegate 메서드는 호출되지 않습니다.

내 슈퍼 클래스 코드

// RecentPhotosMapViewController.h 
@interface RecentPhotosMapViewController : UIViewController <MKMapViewDelegate> 

    @property (nonatomic,strong) NSArray *annotations; 
    @property(nonatomic,weak) IBOutlet MKMapView *mapView; 

@end 


// RecentPhotosMapViewController.m 
- (void)viewDidLoad{ 

     [super viewDidLoad]; 
// Do any additional setup after loading the view. 

    // load annotation data 



     self.mapView.delegate = self; 
} 

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation{ 

MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"]; 

    // safety code 
    if(!aView){ 
     aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"]; 
     aView.canShowCallout = YES; 
     aView.leftCalloutAccessoryView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)]; 
     aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

     } 
    aView.annotation = annotation; 
    [(UIImageView *)aView.leftCalloutAccessoryView setImage:nil]; 

    return aView; 
} 

내 서브 클래스 코드

 // RecentPhotosMapViewControllerWithAnnotationData.h 
    @interface RecentPhotosMapViewControllerWithAnnotationData : RecentPhotosMapViewController 
    @end 

RecentPhotosMapViewControllerWithAnnotationData.m 파일

 -(void) viewDidLoad{ 


// extract annotation data..... 
// set zoom level 


[super viewDidLoad]; 

} 

-(void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view method is called

입니다

도움이 되셨습니다.

답변

1

[super viewDidLoad];을 서브 클래스의 viewDidLoad에서 첫 번째 줄로 이동해보십시오.

위임자를 설정하는 [super viewDidLoad]으로 전화하는 때까지 모든 것이 이미 발생했습니다.

+0

감사는 도움이되지만 처음 난 내 [슈퍼 전에 내 모달을 설정해야 viewDidLoad] 내 하위 클래스에서 다른 제안이 호출됩니다. – shaunak1111

+0

왜 그렇게하고 있는지 재검토하고 싶을 수도 있지만 '[super viewDidLoad]; 앞에 물건을 옮길 수는 있지만 원하는 것을 더 잘 수행 할 수 있다는 것을 명심하십시오. – Ric

0

파생 클래스의 viewDidLoad 방법의 마지막 행으로지도보기 대의원 할당 라인을 유지 :

RecentPhotosMapViewControllerWithAnnotationData.m

-(void) viewDidLoad 
{ 

// extract annotation data..... 
// set zoom level 

[super viewDidLoad]; 

self.mapView.delegate = self; 

} 
관련 문제