2013-04-09 65 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