2012-07-25 96 views
1

我試圖完成cs193p分配5的最後部分(link的MKMapView委託方法不會被調用-calloutaccessorycontroltapped

的應用程序選擇從Flickr和情節的照片熱鬧的地方從地圖上那些地方。

它的任務5C它說

在地圖上每個註釋應該有它顯示下列標註: ℃。顯示所選照片的​​完整圖像的揭示按鈕(就像用戶從桌面上選擇照片一樣)或者在該位置顯示照片列表(同樣,就像用戶選擇了該地方一樣從一張桌子)。

我已經完成了顯示標註的前幾部分,並將縮略圖加載到標註中。

我已經設置了我的mapViewController作爲mapView的委託,我知道它的工作原理,因爲當我點擊pin時,它會調用didSelectAnnotationView方法,它也在我的mapViewController中,並且所有運行正常,並在標註中實際顯示披露配件。

但是,我還定義了方法calloutAccessoryControlTapped(相同的VC),並且此方法不會被調用。完全一樣。目前,我剛剛在那裏獲得了一個NSLog,並沒有出現。

嗯,我什麼也沒說,只是爲了讓它更奇怪,有一個註釋,它在數以百計的作品中不起作用。

從第一個地方的一個註釋激發按鈕,但沒有別的。是因爲它是第一個註釋嗎?按鈕只是爲此而開火嗎?

我想後的代碼,但它是不是真的知道如何相關:

@interface flickrthingMapViewController()<MKMapViewDelegate> 
    @property (weak, nonatomic) IBOutlet MKMapView *mapview; 

    @end 

    @implementation flickrthingMapViewController 
    @synthesize delegate = _delegate; 

    @synthesize mapview = _mapview; 
    @synthesize annotations = _annotations; 


    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     self.mapview.delegate = self; //remembered to set the delegate 

    } 
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView 
{ 
    if (![aView.annotation isKindOfClass:[flickrthingPlaceAnnotation class]]) 
    { 
     UIImage *image = [self.delegate flickrthingMapViewContoller:self imageForAnnotation:aView.annotation]; 


     [(UIImageView *)aView.leftCalloutAccessoryView setImage:image]; 
    } 
    UIButton *buttonToViewDetails = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    aView.rightCalloutAccessoryView=buttonToViewDetails; 


} 

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)aView calloutAccessoryControlTapped:(UIControl *)control 
{ 

    NSLog(@"hello"); 
} 

每隔問題,我問過原來我已經做了一些愚蠢的,而且我希望是這樣的這裏的情況。但我一直在坐着看着它,看不到它!

感謝您的見解!

回答

2

事實證明,在didSelectAnnotationView中添加按鈕爲時已晚!

我以爲我試圖通過不創建按鈕有效,除非有人真的選擇了註釋,但事實證明(出於某種原因?)如果按鈕是在didSelectAnnotationView中創建的,它不會觸發委託方法。

我已經將它移入viewForAnnotation方法,它的工作原理!