从另一个视图中的 MKMapView 中删除注释

发布于 2024-09-01 18:24:44 字数 765 浏览 5 评论 0原文

我有两种看法。第一个是带有一些注释的 MKMapView。单击 UIButton 会将第二个视图推送到堆栈上。它有一个 UITableView ,其中包含与地图注释相对应的注释列表。那么,当您单击删除按钮时,如何调用另一个视图中的 MKMapView ,以便删除注释。我的 MKMapView 是在我的应用程序委托以及我当前的类中声明的。我正在尝试使用以下内容,但它不起作用:

RideAppDelegate *appDelegate = (RideAppDelegate *)[[UIApplication sharedApplication] delegate];
Annotation *ano;
CLLocationCoordinate2D anoPoint;
anoPoint.latitude = [[eventToDelete valueForKey:@"latitude"] doubleValue];
anoPoint.longitude = [[eventToDelete valueForKey:@"longitude"] doubleValue];
ano = [[[Annotation alloc] init] autorelease];
ano.coordinate = anoPoint;
[appDelegate.ridesMap removeAnnotation: ano];
[appDelegate release];

我一定是尝试错误地访问其他视图的 MKMapView 吗?

I have two views. The first is a MKMapView with some annotations. Clicking a UIButton pushes a second view on the stack. This has a UITableView with a list of annotations which correspond to the map annotations. So, when you click the delete button, how can I call my MKMapView which is in another view, so that I can remove the annotation. My MKMapView is declared in my app delegate, as well as my current class. I am trying to use the following, but it is not working:

RideAppDelegate *appDelegate = (RideAppDelegate *)[[UIApplication sharedApplication] delegate];
Annotation *ano;
CLLocationCoordinate2D anoPoint;
anoPoint.latitude = [[eventToDelete valueForKey:@"latitude"] doubleValue];
anoPoint.longitude = [[eventToDelete valueForKey:@"longitude"] doubleValue];
ano = [[[Annotation alloc] init] autorelease];
ano.coordinate = anoPoint;
[appDelegate.ridesMap removeAnnotation: ano];
[appDelegate release];

I must be trying to access the MKMapView of my other view incorrectly?

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

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

发布评论

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

评论(1

瑶笙 2024-09-08 18:24:44
  • ridesMap 必须是 MKMapView,它必须是 appDelegate 的 ivar。它是具有(保留)的财产吗?它是使用 self.ridesMap = [[MKMapView alloc] init] 或类似方法创建和分配的吗?
  • 您确定 Annotation 遵循 MKAnnotation 协议吗?

(为什么要释放 appDelegate?您不拥有或保留它。)

  • ridesMap must be the MKMapView which must be an ivar of appDelegate. Is it a property with (retain)? Is it created and assigned with self.ridesMap = [[MKMapView alloc] init] or similar?
  • You are sure Annotation follows MKAnnotation protocol?

(why release the appDelegate? You don't own or retain it.)

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