iOS MapKit didAddAnnotationViews 方法未调用

发布于 2024-10-22 19:38:02 字数 1513 浏览 5 评论 0原文

一旦数据被解析,我试图从一个单独的类加载注释。数据解析正确,我通过 NSLog 进行跟踪。我将数据发送到负责加载 MKMapView 的类。该类接收到正确的数据。

下面是解析我的数据的类的代码 (ParseData.m):

AnnotationsTest *loadFriend = [[AnnotationsTest alloc] init];
    [loadFriend loadOutAnnotations:friendFound];
    [loadFriend loadOutAnnotationsAgain];
    [loadFriend release];

在我的第二个类 (MapViewController.m) 中调用的方法:

-(void)loadOutAnnotations:(NSMutableArray *)friendData

使用以下代码:

    CLLocationCoordinate2D workingCoordinate;

workingCoordinate.latitude = [[friendData objectAtIndex:5] floatValue];
workingCoordinate.longitude = [[friendData objectAtIndex:4] floatValue];
MapAnnotation *appleStore1 = [[MapAnnotation alloc] initWithCoordinate:workingCoordinate];
[appleStore1 setTitle:@"Title"];
[appleStore1 setSubtitle:@"subtitle"];
[appleStore1 setUserData:[friendData objectAtIndex:6]];
[appleStore1 setAnnotationType:iCodeBlogAnnotationTypeApple];

[self.mapView addAnnotation:appleStore1];

最后,这是我响应 addAnotation 事件的代码 ( MapViewController.m):

- (void)mapView:(MKMapView *)mapViews didAddAnnotationViews:(NSArray *)views {
id myAnnotation = [mapViews.annotations objectAtIndex:0];
[mapViews selectAnnotation:myAnnotation animated:YES];
NSLog(@"didAddAnnotationViews is called");}

如果我对变量进行硬编码,不通过方法传递 NSMutableArray,并调用 MapViewController 类 viewDidLoad 部分中的方法,则注释将完美加载。当我尝试调用该方法从另一个类添加注释时,didAddAnnotationViews 方法没有响应。

请指教。提前致谢!!

埃文

I'm trying to load annotations from a separate class once data has been parsed. The data is parsing correctly which I follow through the NSLog. I am sending the data to the class responsible for loading the MKMapView. This class receives the correct data.

Here is the code for the class that parses my data (ParseData.m):

AnnotationsTest *loadFriend = [[AnnotationsTest alloc] init];
    [loadFriend loadOutAnnotations:friendFound];
    [loadFriend loadOutAnnotationsAgain];
    [loadFriend release];

The method being called in my second class (MapViewController.m):

-(void)loadOutAnnotations:(NSMutableArray *)friendData

with the following code:

    CLLocationCoordinate2D workingCoordinate;

workingCoordinate.latitude = [[friendData objectAtIndex:5] floatValue];
workingCoordinate.longitude = [[friendData objectAtIndex:4] floatValue];
MapAnnotation *appleStore1 = [[MapAnnotation alloc] initWithCoordinate:workingCoordinate];
[appleStore1 setTitle:@"Title"];
[appleStore1 setSubtitle:@"subtitle"];
[appleStore1 setUserData:[friendData objectAtIndex:6]];
[appleStore1 setAnnotationType:iCodeBlogAnnotationTypeApple];

[self.mapView addAnnotation:appleStore1];

And finally, here is my code to respond to the addAnotation events (MapViewController.m):

- (void)mapView:(MKMapView *)mapViews didAddAnnotationViews:(NSArray *)views {
id myAnnotation = [mapViews.annotations objectAtIndex:0];
[mapViews selectAnnotation:myAnnotation animated:YES];
NSLog(@"didAddAnnotationViews is called");}

The annotation will load perfectly if I hard code the variables, don't pass the NSMutableArray through the method, and call upon the method in the MapViewController class viewDidLoad section. When I try to call upon the method to add annotations from another class, the didAddAnnotationViews method does not respond.

Please advise. Thanks in advance!!

Evan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2024-10-29 19:38:02

所以我查看了您的代码,它是预期的行为:地图注释只是注释的抽象表示。您必须“手动”将其添加到地图中。然后,地图向委托询问它应该用来显示注释的视图。因此,当您不将其添加到地图时,它不会显示也就不足为奇了:)

So I looked at your code and it's expected behavior: A map annotation is just the abstract representation of an annotation. You do have to "manually" add it to the map. The map THEN asks the delegate for the VIEW it should use to DISPLAY the annotation. So it's no wonder it's not showing up when you don't add it to the map :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文