2013-04-09 61 views
0

我想在點擊地圖標註中的披露按鈕時加載另一個視圖。MapView標註上的細節披露按鈕將不會響應水龍頭

我使用添加按鈕標註在我AnnotationView實現文件的initWithAnnotation方法如下(我只顯示相關的代碼):

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier 

{ 

self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

} 

我還增加了以下controllTapped方法對我的MapViewController執行文件,用於檢測揭示按鈕被竊聽的時間:

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

{ 

    DetailViewController *dvc = [[DetailViewController alloc] init]; 
    [self.navigationController pushViewController:dvc animated:YES]; 



} 

我還爲UI創建了一個帶有.XIB的新的detailedDisclosure類。這是我想在用戶點擊披露按鈕時加載的視圖。

那麼,當用戶點擊披露按鈕時,爲什麼沒有發生?

回答

1
UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
[btnGo addTarget:self action:@selector(goToLocation:) forControlEvents:UIControlEventTouchUpInside]; 
pinView.rightCalloutAccessoryView=btnGo; 


-(void) goToLocation:(UIButton *) sender 
{ 
} 
+0

你是說我要用這個替換當前的公開按鈕語法嗎?在(id)initWithAnnotation ....方法中?此外,goToLocation括號中會包含什麼內容? pushViewController語法? – Cybernetic 2013-04-10 13:53:33

0

你必須使用MKMapView委託方法用於此目的的類似以下,用於識別您的CustomAnnotationClass

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    id <MKAnnotation> annotation = [view annotation]; 
    if ([annotation isKindOfClass:[CustomAnnotationClass class]]) 
    { 
     DetailViewController *dvc = [[DetailViewController alloc] init]; 
     [self.navigationController pushViewController:dvc animated:YES]; 
    } 
} 

讓我硝酸鉀,如果你得到它的工作。

+0

仍然沒有任何反應。如果我設置了斷點,我可以看到程序輸入IF語句。看來,pushViewController沒有做任何事情。我可以錯過某種連接到我的detailViewController嗎?它是否需要一些操作方法和/或插座來沿着DisclosureButton?或者是否需要在頭文件中聲明controlTapped方法? – Cybernetic 2013-04-10 14:16:21

+0

如果它進入IF語句,那麼你的問題只是找出爲什麼detailViewController沒有被推送。你可以試試'DetailViewController * dvc = [[DetailViewController alloc] initWithNibName:@「DetailViewController」bundle:nil];' – viral 2013-04-10 18:33:24