对不起,我已经阅读了一堆教程如何为MapKit注释创建自定义标注。它适用于NSLog,但我无法在标注中显示信息。EDITED:MapKit注释标注。调整UIPopoverController的大小
我在地图上有两种类型的图标。这是我的viewForAnnotation方法:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if (! [annotation isKindOfClass:[IGAMapAnnotation class]]) {
return nil;
}
IGAMapAnnotation *myLocation = (IGAMapAnnotation *) annotation;
self.typeIsFix = [myLocation.navaidType isEqualToString:@"FIX"];
self.typeIsPort = [myLocation.navaidType isEqualToString:@"PORT"];
int planeImageViewTag = 42;
NSString *reuseId;
if (self.typeIsPort)
reuseId = @"IGAMapAnnotationPort";
else if (self.typeIsFix)
reuseId = @"IGAMapAnnotationFix";
else
reuseId = @"IGAMapAnnotationOther";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (annotationView == nil)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
annotationView.enabled = YES;
UIButton *annotationInfo = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView = annotationInfo;
annotationView.canShowCallout = YES;
if (self.typeIsPort)
{
annotationView.image = [UIImage imageNamed:@"mapPORT.png"];
annotationView.centerOffset = CGPointMake(0, 0);
}
else if (self.typeIsFix)
{
annotationView.image = [UIImage imageNamed:@"mapFIX.png"];
annotationView.centerOffset = CGPointMake(0, 0);
}
else
return nil;
}
else
{
annotationView.annotation = annotation;
}
return annotationView;
}
然后,我有一个calloutAccessoryControlTapped方法
- (void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
IGAAnnotationInfoViewController *popOverCallout = [[IGAAnnotationInfoViewController alloc]init];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:popOverCallout];
popOver.popoverContentSize = CGSizeMake(300, 200);
[popOver presentPopoverFromRect:view.bounds
inView:view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
我也创建了我分配到UIPopoverController一个UIViewController。
现在,当我点击我的注释按钮时,我看到一个文本的空白区域。大。如果我将文本分配到的UIViewController一个标签,它也是伟大工程(以下是我的UIViewController.m):
- (void)viewDidLoad {
[super viewDidLoad];
txtCallout = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 300, 200) ];
txtCallout.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(14.0)];
txtCallout.numberOfLines = 0;
txtCallout.clipsToBounds = YES;
txtCallout.backgroundColor = [UIColor clearColor];
txtCallout.textColor = [UIColor blackColor];
txtCallout.textAlignment = NSTextAlignmentLeft;
txtCallout.text = @"text\ntext\ntext";
[self.view addSubview:txtCallout];
}
但是我怎么插入来自我的标注方法的文本?此外,文本必须根据图标类型而不同,例如@“PORT,PORT”或@“FIX,FIX”。我该怎么做?
编辑:
我设法显示标注与必要的信息传递。我的最后一个问题是,有时我的标注是3行,有时是 - 多达15行。怎样才能使标注自动调整到我的字符串中的行数?我应该在UIViewController中修改我的popoverContentSize或我的标签大小吗?
太谢谢你了!