当我点击地图标注中的公开按钮时,我想加载另一个视图。
我在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的新详细的Disclosure类。这是我想在用户点击公开按钮时加载的视图。
当用户点击披露按钮时,为什么没有发生任何事情?
答案 0 :(得分:1)
UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[btnGo addTarget:self action:@selector(goToLocation:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView=btnGo;
-(void) goToLocation:(UIButton *) sender
{
}
答案 1 :(得分: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];
}
}
让我知道,如果你让它发挥作用。