嗨,我的应用中有一个地图视图页面,其中显示了 200 多个标记。
我目前发起这些
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:currentobjectarray.title andCoordinate:location];
单击标记时,这些会生成一个文本标签。如何将按钮添加到注释视图,以便在单击它时可以导航到所选标记的“更多信息”页面?我不确定它的按钮部分。
非常感谢任何帮助
嗨,我的应用中有一个地图视图页面,其中显示了 200 多个标记。
我目前发起这些
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:currentobjectarray.title andCoordinate:location];
单击标记时,这些会生成一个文本标签。如何将按钮添加到注释视图,以便在单击它时可以导航到所选标记的“更多信息”页面?我不确定它的按钮部分。
非常感谢任何帮助
您需要创建一个UIButton并将其分配给rightCalloutAccessoryView您的 MKAnnotationView 的属性。
在mapView:viewForAnnotation:返回自定义MKAnnotationView实例的方法中,插入此代码以创建按钮并将其与操作相关联。
我假设您的MKAnnotationView实例被调用annotationView并且您要调用的方法是presentMoreInfo.
UIButton * disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[disclosureButton addTarget:self
action:@selector(presentMoreInfo)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = disclosureButton;
你的presentMoreInfo方法可以是
- (void)presentMoreInfo {
DetailsViewController * detailsVC = [DetailsViewController new];
//configure your view controller
//...
[self.navigationController pushViewController:detailsVC animated:YES];
}