在 MKMapView 上尝试多个注释时出现 SIGABRT 错误

发布于 2024-12-09 00:27:51 字数 7492 浏览 0 评论 0原文

我一直在使用 MKMapView 并在地图上放置注释图钉。我正在努力在地图上为 30 个不同位置放置 30 个图钉,并确保在添加每个附加位置后运行 iPhone SDK。然后,不知怎的,它开始崩溃并给我带来了可怕的“SIGABRT”。 AG!!

我知道这可能是我的语法中的一个小错误,但由于我刚刚复制并粘贴了以前有效的代码,所以我不知所措。我正在考虑使用 MKCooperativeRegionMake 让一切变得更加简洁(我读到这可能是一个选项),但我已经输入了 10 个商店之类的东西,所以需要很多时间来切换它,这是我不想要的如果这是一个快速修复的话。

我继续取出除一个坐标之外的所有坐标,结果成功了。然后我又添加了一个,它工作了,等等。出于某种原因,它工作了很多次,但有时它会锁定并崩溃。我认为这只是特定位置存在问题,但似乎从来都不是任何特定位置的语法问题。所以现在我对造成这种情况的原因感到茫然。

我想这可能是分配和释放的问题,我做得不对?我试图在代码期间“释放”某些分配的空间,但问题仍然存在。我也尝试在代码期间不释放分配的空间来做到这一点,同样的问题。

这是我正在使用的代码(所有代码有时都有效,因此我已在 MillersLocations 文件中正确设置了标题、副标题和坐标):

MapViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Miller's Neighborhood Market #56
    MKCoordinateRegion store56;
    store56.center.latitude = 36.8605679;
    store56.center.longitude = -76.2866713;
    store56.span.latitudeDelta = 0.1;
    store56.span.longitudeDelta = 0.1;
    [mapView setRegion:store56 animated:YES];

    MillersLocations *ann56 = [[MillersLocations alloc]init];
    ann56.title = @"Store #56";
    ann56.subtitle = @"Come check us out!";
    ann56.coordinate = store56.center;
    [mapView addAnnotation:ann56];
    [MillersLocations release];
    //Not sure if release should be on this syntax


    //Miller's Neighborhood Market #66
    MKCoordinateRegion store66;
    store66.center.latitude = 37.0942970;
    store66.center.longitude = -76.4584890;
    store66.span.latitudeDelta = 0.1;
    store66.span.longitudeDelta = 0.1;
    [mapView setRegion:store66 animated:YES]; 

    MillersLocations *ann66 = [[MillersLocations alloc]init];
    ann66.title = @"Store #66";
    ann66.subtitle = @"Come check us out!";
    ann66.coordinate = store66.center;
    [mapView addAnnotation:ann66];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #21
    MKCoordinateRegion store21;
    store21.center.latitude = 37.0385289;
    store21.center.longitude = -76.4004810;
    store21.span.latitudeDelta = 0.1;
    store21.span.longitudeDelta = 0.1;
    [mapView setRegion:store21 animated:YES];    

    MillersLocations *ann21 = [[MillersLocations alloc]init];
    ann21.title = @"Store #21";
    ann21.subtitle = @"Come check us out!";
    ann21.coordinate = store21.center;
    [mapView addAnnotation:ann21];
    [MillersLocations release];
    //Not sure if release should be on this syntax


    //Miller's Neighborhood Market #67
    MKCoordinateRegion store67;
    store67.center.latitude = 37.6823690;
    store67.center.longitude = -77.5898330;
    store67.span.latitudeDelta = 0.1;
    store67.span.longitudeDelta = 0.1;
    [mapView setRegion:store67 animated:YES];

    MillersLocations *ann67 = [[MillersLocations alloc]init];
    ann67.title = @"Store 67";
    ann67.subtitle = @"Come check us out";
    ann67.coordinate = store67.center;
    [mapView addAnnotation:ann67];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #49
    MKCoordinateRegion store49;
    store49.center.latitude = 36.8550990;
    store49.center.longitude = -76.1355950;
    store49.span.latitudeDelta = 0.1;
    store49.span.latitudeDelta = 0.1;
    [mapView setRegion:store49 animated:YES];

    MillersLocations *ann49 = [[MillersLocations alloc]init];
    ann49.title = @"Store 49";
    ann49.subtitle = @"Come check us out";
    ann49.coordinate = store49.center;
    [mapView addAnnotation:ann49];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #82
    MKCoordinateRegion store82;
    store82.center.latitude = 36.7848840;
    store82.center.longitude = -76.1587459;
    store82.span.latitudeDelta = 0.1;
    store82.span.latitudeDelta = 0.1;
    [mapView setRegion:store82 animated:YES];

    MillersLocations *ann82 = [[MillersLocations alloc]init];
    ann82.title = @"Store 82";
    ann82.subtitle = @"Come check us out";
    ann82.coordinate = store82.center;
    [mapView addAnnotation:ann82];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #40
    MKCoordinateRegion store40;
    store40.center.latitude = 37.1236680;
    store40.center.longitude = -76.5093960;
    store40.span.latitudeDelta = 0.1;
    store40.span.latitudeDelta = 0.1;
    [mapView setRegion:store40 animated:YES];

    MillersLocations *ann40 = [[MillersLocations alloc]init];
    ann40.title = @"Store 40";
    ann40.subtitle = @"Come check us out";
    ann40.coordinate = store40.center;
    [mapView addAnnotation:ann40];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #55
    MKCoordinateRegion store55;
    store55.center.latitude = 36.7704630;
    store55.center.longitude = -76.6058140;
    store55.span.latitudeDelta = 0.1;
    store55.span.latitudeDelta = 0.1;
    [mapView setRegion:store55 animated:YES];

    MillersLocations *ann55 = [[MillersLocations alloc]init];
    ann55.title = @"Store 55";
    ann55.subtitle = @"Come check us out";
    ann55.coordinate = store55.center;
    [mapView addAnnotation:ann55];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #58
    MKCoordinateRegion store58;
    store58.center.latitude = 36.7818390;
    store58.center.longitude = -76.0479090;
    store58.span.latitudeDelta = 0.1;
    store58.span.latitudeDelta = 0.1;
    [mapView setRegion:store58 animated:YES];

    MillersLocations *ann58 = [[MillersLocations alloc]init];
    ann58.title = @"Store 58";
    ann58.subtitle = @"Come check us out";
    ann58.coordinate = store58.center;
    [mapView addAnnotation:ann58];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #57
    MKCoordinateRegion store57;
    store57.center.latitude = 36.8216160;
    store57.center.longitude = -76.4246680;
    store57.span.latitudeDelta = 0.1;
    store57.span.latitudeDelta = 0.1;
    [mapView setRegion:store57 animated:YES];

    MillersLocations *ann57 = [[MillersLocations alloc]init];
    ann57.title = @"Store 57";
    ann57.subtitle = @"Come check us out";
    ann57.coordinate = store57.center;
    [mapView addAnnotation:ann57];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #90
    MKCoordinateRegion store90;
    store90.center.latitude = 38.1330690;
    store90.center.longitude = -77.5124230;
    store90.span.latitudeDelta = 0.1;
    store90.span.latitudeDelta = 0.1;
    [mapView setRegion:store90 animated:YES];

    MillersLocations *ann90 = [[MillersLocations alloc]init];
    ann90.title = @"Store 90";
    ann90.subtitle = @"Come check us out";
    ann90.coordinate = store90.center;
    [mapView addAnnotation:ann90];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //56,66,21,67,49,90,82,40,55,58,57

}

错误(线程 1:程序收到信号“SIGABRT”。 )总是在线上发生:

[mapView setRegion:store57animated:YES];

或者在 store90 上也可以。还有其他商店也发生过这种情况,但总是在那条线上。我没有确定任何押韵或理由。

感谢任何可以提供帮助的人!如果我有点啰嗦,请道歉,我只是想确保我包含了您需要帮助的任何信息。

编辑

一旦我正确地合成了我创建的 MKMapView Outlet,然后获得了释放它的代码(“[mapView release];”),它就起作用了。我假设 MapViews 释放自己,这可能是错误的原因。

它工作得很好,然后我去添加另一个注释,它又崩溃了。当我删除新注释时它会起作用,因此当我添加更多注释时会出现问题。股份公司。任何帮助表示赞赏。谢谢。

I've been working with MKMapView and am placing Annotation Pins on the map. I'm working towards placing 30 pins in the map for 30 different locations and made sure to run the iPhone SDK after adding each additional location. Then, out of nowhere, it started crashing and giving me the dreaded 'SIGABRT'. AG!!

I know that it could possibly be a slight mistake in my syntax but since I've just been copying and pasting code that previously worked, I'm at a loss. I'm considering using MKCoordinateRegionMake to make everything more concise (I read that this could be an option) BUT I've already entered something like 10 stores so it would require a lot of time to switch it over, which I don't want to do if this is a quick fix.

I proceeded to take out all but one coordinate and it worked. Then I added one more back and it worked, etc. For some reason, it worked a bunch of the times, but sometimes it would lock up and crash. I thought it was just specific locations that were a problem but it never seemed to be a problem with the syntax of any location in particular. So now I'm at a loss for what is causing it.

I'm thinking it may be an issue of allocating and releasing that I'm not doing right? I've attempted to "release" certain allocated space during the code but the problem persisted. I also attempted to do it without releasing allocated space during the code, same problem.

Here's the code I'm working with (all the code worked at times, so I've set up title, subtitle and coordinate in the MillersLocations file correctly):

MapViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Miller's Neighborhood Market #56
    MKCoordinateRegion store56;
    store56.center.latitude = 36.8605679;
    store56.center.longitude = -76.2866713;
    store56.span.latitudeDelta = 0.1;
    store56.span.longitudeDelta = 0.1;
    [mapView setRegion:store56 animated:YES];

    MillersLocations *ann56 = [[MillersLocations alloc]init];
    ann56.title = @"Store #56";
    ann56.subtitle = @"Come check us out!";
    ann56.coordinate = store56.center;
    [mapView addAnnotation:ann56];
    [MillersLocations release];
    //Not sure if release should be on this syntax


    //Miller's Neighborhood Market #66
    MKCoordinateRegion store66;
    store66.center.latitude = 37.0942970;
    store66.center.longitude = -76.4584890;
    store66.span.latitudeDelta = 0.1;
    store66.span.longitudeDelta = 0.1;
    [mapView setRegion:store66 animated:YES]; 

    MillersLocations *ann66 = [[MillersLocations alloc]init];
    ann66.title = @"Store #66";
    ann66.subtitle = @"Come check us out!";
    ann66.coordinate = store66.center;
    [mapView addAnnotation:ann66];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #21
    MKCoordinateRegion store21;
    store21.center.latitude = 37.0385289;
    store21.center.longitude = -76.4004810;
    store21.span.latitudeDelta = 0.1;
    store21.span.longitudeDelta = 0.1;
    [mapView setRegion:store21 animated:YES];    

    MillersLocations *ann21 = [[MillersLocations alloc]init];
    ann21.title = @"Store #21";
    ann21.subtitle = @"Come check us out!";
    ann21.coordinate = store21.center;
    [mapView addAnnotation:ann21];
    [MillersLocations release];
    //Not sure if release should be on this syntax


    //Miller's Neighborhood Market #67
    MKCoordinateRegion store67;
    store67.center.latitude = 37.6823690;
    store67.center.longitude = -77.5898330;
    store67.span.latitudeDelta = 0.1;
    store67.span.longitudeDelta = 0.1;
    [mapView setRegion:store67 animated:YES];

    MillersLocations *ann67 = [[MillersLocations alloc]init];
    ann67.title = @"Store 67";
    ann67.subtitle = @"Come check us out";
    ann67.coordinate = store67.center;
    [mapView addAnnotation:ann67];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #49
    MKCoordinateRegion store49;
    store49.center.latitude = 36.8550990;
    store49.center.longitude = -76.1355950;
    store49.span.latitudeDelta = 0.1;
    store49.span.latitudeDelta = 0.1;
    [mapView setRegion:store49 animated:YES];

    MillersLocations *ann49 = [[MillersLocations alloc]init];
    ann49.title = @"Store 49";
    ann49.subtitle = @"Come check us out";
    ann49.coordinate = store49.center;
    [mapView addAnnotation:ann49];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #82
    MKCoordinateRegion store82;
    store82.center.latitude = 36.7848840;
    store82.center.longitude = -76.1587459;
    store82.span.latitudeDelta = 0.1;
    store82.span.latitudeDelta = 0.1;
    [mapView setRegion:store82 animated:YES];

    MillersLocations *ann82 = [[MillersLocations alloc]init];
    ann82.title = @"Store 82";
    ann82.subtitle = @"Come check us out";
    ann82.coordinate = store82.center;
    [mapView addAnnotation:ann82];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #40
    MKCoordinateRegion store40;
    store40.center.latitude = 37.1236680;
    store40.center.longitude = -76.5093960;
    store40.span.latitudeDelta = 0.1;
    store40.span.latitudeDelta = 0.1;
    [mapView setRegion:store40 animated:YES];

    MillersLocations *ann40 = [[MillersLocations alloc]init];
    ann40.title = @"Store 40";
    ann40.subtitle = @"Come check us out";
    ann40.coordinate = store40.center;
    [mapView addAnnotation:ann40];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #55
    MKCoordinateRegion store55;
    store55.center.latitude = 36.7704630;
    store55.center.longitude = -76.6058140;
    store55.span.latitudeDelta = 0.1;
    store55.span.latitudeDelta = 0.1;
    [mapView setRegion:store55 animated:YES];

    MillersLocations *ann55 = [[MillersLocations alloc]init];
    ann55.title = @"Store 55";
    ann55.subtitle = @"Come check us out";
    ann55.coordinate = store55.center;
    [mapView addAnnotation:ann55];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #58
    MKCoordinateRegion store58;
    store58.center.latitude = 36.7818390;
    store58.center.longitude = -76.0479090;
    store58.span.latitudeDelta = 0.1;
    store58.span.latitudeDelta = 0.1;
    [mapView setRegion:store58 animated:YES];

    MillersLocations *ann58 = [[MillersLocations alloc]init];
    ann58.title = @"Store 58";
    ann58.subtitle = @"Come check us out";
    ann58.coordinate = store58.center;
    [mapView addAnnotation:ann58];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #57
    MKCoordinateRegion store57;
    store57.center.latitude = 36.8216160;
    store57.center.longitude = -76.4246680;
    store57.span.latitudeDelta = 0.1;
    store57.span.latitudeDelta = 0.1;
    [mapView setRegion:store57 animated:YES];

    MillersLocations *ann57 = [[MillersLocations alloc]init];
    ann57.title = @"Store 57";
    ann57.subtitle = @"Come check us out";
    ann57.coordinate = store57.center;
    [mapView addAnnotation:ann57];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //Miller's Neighborhood Market #90
    MKCoordinateRegion store90;
    store90.center.latitude = 38.1330690;
    store90.center.longitude = -77.5124230;
    store90.span.latitudeDelta = 0.1;
    store90.span.latitudeDelta = 0.1;
    [mapView setRegion:store90 animated:YES];

    MillersLocations *ann90 = [[MillersLocations alloc]init];
    ann90.title = @"Store 90";
    ann90.subtitle = @"Come check us out";
    ann90.coordinate = store90.center;
    [mapView addAnnotation:ann90];
    [MillersLocations release];
    //Not sure if release should be on this syntax

    //56,66,21,67,49,90,82,40,55,58,57

}

The error (Thread 1: Program received signal "SIGABRT".) always happens on the line:

[mapView setRegion:store57 animated:YES];

OR on store90 as well. There's other stores it's happened on too but always on that line. No rhyme or reason that I've determined.

Thanks to anyone that can help! Apologize if I'm a little long-winded, I just wanted to make sure I included any information you'd need to help.

EDIT

It worked once I properly synthesized the MKMapView Outlet that I created and then got of the code to release it ("[mapView release];"). I'm assuming MapViews release themselves which would have been the cause of the error.

It worked fine and then I went to add another annotation and it crashed again. When I delete the new annotation it works, so there's a problem when I add more. AG. Any help is appreciated. Thanks.

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

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

发布评论

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

评论(1

笨笨の傻瓜 2024-12-16 00:27:51

SIGABRT 的最可能原因是 store49 的区域无效,导致 NSInvalidArgumentException 和 SIGABRT。

对于 store49(以及之后的所有商店),未设置 longitudeDelta
仅设置了latitudeDelta(两次)。

将重复的 latitudeDelta 设置修复为 longitudeDelta

另一个问题是:

[MillersLocations release];

这会尝试调用 MillersLocation 类上的 release,而不是您正在创建的该类的实例。所有这些行都应该更改为类似以下内容:

[ann56 release];

此外,您不需要每次都创建一个区域来设置注释。例如,您可以这样做:

MillersLocations *ann56 = [[MillersLocations alloc]init];
ann56.title = @"Store #56";
ann56.subtitle = @"Come check us out!";
ann56.coordinate = CLLocationCoordinate2DMake(36.8605679, -76.2866713);
[mapView addAnnotation:ann56];
[ann56 release];

添加所有注释后,您可以创建一个包含所有注释的区域(如果这是您想要的),或者仅显示最后一个注释,然后调用 setRegion一次在最后。

此外,您可能希望将存储存储在 plist 中并循环遍历 plist 以创建注释,而不是在代码中单独创建它们。

最后,您不应该删除 [mapView release]; (来自 dealloc),即使它是 IBOutlet。

The most likely reason for the SIGABRT is that the region for store49 is invalid resulting in an NSInvalidArgumentException and the SIGABRT.

For store49 (and all the stores after that), the longitudeDelta is not being set.
Only the latitudeDelta is being set (twice).

Fix the duplicate latitudeDelta settings to longitudeDelta.

Another problem is this:

[MillersLocations release];

This attempts to call release on the MillersLocation class--not the instance of that class you are creating. All those lines should be changed to something like:

[ann56 release];

Also, you don't need to create a region every time to set up an annotation. For example, you can just do this:

MillersLocations *ann56 = [[MillersLocations alloc]init];
ann56.title = @"Store #56";
ann56.subtitle = @"Come check us out!";
ann56.coordinate = CLLocationCoordinate2DMake(36.8605679, -76.2866713);
[mapView addAnnotation:ann56];
[ann56 release];

After adding all the annotations, then you can create a region that encloses all the annotations (if that's what you want) or just shows the last annotation and then call setRegion once at the end.

Also, you may want to store the stores in a plist and loop through the plist to create the annotations instead of creating them separately in code.

Finally, you should not remove the [mapView release]; (from dealloc) even if it is an IBOutlet.

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