我想知道是否有可能做到这一点,或者如果不是,有什么替代方案?我需要一些需要在地图上显示的信息,但我在这方面遇到了问题...MKPointAnnotation提供了一个很好的界面,但是我还没能一次打开一个以上的标注。谢谢!
发布于 2012-05-06 21:24:43
我找到了解决方案:
您需要先阅读以下内容:
http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html
这里有一个例子:
http://shawnsbits.com/blog/2011/04/12/custom-map-pins-for-mapkit/
关键是在viewDidLoad中加载带有自定义图像的注释数组,然后在mapView:viewForAnnotation:创建一个新的MKAnnotationView,并通过将注释转换为传递给它的自定义注释将图像加载到其中。
我希望这能帮到你。如果它看起来有点混乱,很抱歉!
发布于 2012-05-06 11:15:41
在注释中添加按钮和为button.You设置标签也可以与自定义注释一起使用,但在底线方法与below.You相同,需要为打开多个注释设置标识符(标签)。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
{
MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.map dequeueReusableAnnotationViewWithIdentifier: @"restMap"];
if (pin == nil) {
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"restMap"] autorelease];
}
else {
pin.annotation = annotation;
}
// add cutom button by following way.
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeCustombutton];
// you just need to find an integer value that matches your object in some way:
// its index in your array of MKAnnotation items, or an id of some sort, etc
NSInteger annotationValue = [self.annotations indexOfObject:annotation];
// set the tag property of the button to the index
detailButton.tag = annotationValue;
pin.rightCalloutAccessoryView = detailButton;
return pin;
}
-(IBAction)showDetailofannotation:(UIView*)sender {
// get the tag value from the sender
NSInteger annotationtag = sender.tag;
MyAnnotationObject *selectedObject = [self.annotations objectAtIndex:annotationtag ];
// now you know which detail view you want to show; the code that follows
YourDetailViewController *detailView = [[YourDetailViewController alloc] initWithNibName:@"YourDetailViewController ", NSBundle:nil];
detailView.detailObject = selectedObject;
[[self navigationController] pushViewController:detailView animated:YES];
[detailView release];`
}希望,这会帮助你..
https://stackoverflow.com/questions/10467737
复制相似问题