为什么这会产生错误——幽灵 NSArray?

发布于 2024-12-22 21:09:18 字数 1685 浏览 4 评论 0原文

当我启用(取消注释)这行代码时,我遇到了 SIGABRT 崩溃 - 这对我来说很奇怪,因为我以前从未遇到过这个问题。

cell.textLabel.text = [[annotations objectAtIndex:indexPath.row] title];

我得到的错误是:

2011-12-28 14:03:00.118 MapWithTableModalView-001[2006:11603] 本地化名称数据库不存在 2011-12-28 14:03:01.110 MapWithTableModalView-001[2006:11603] * 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayM objectAtIndex:]:索引 0 超出空数组的边界'

该项目不会产生错误或警告。

该项目基于 2 个 UIViewController,它们通过按钮 - ModalViewContoller 在彼此之上滑动。当我按下按钮时,就会发生崩溃。

只需在此处添加代码 - 它是教程的一部分,但我仍然想得到它:-) 我知道这看起来不像普通数组,但数据在项目中是这样设置的。一旦我弄清楚了这一点,我想将它设置在 Plist 中。

-(void)loadOurAnnotations
    {
CLLocationCoordinate2D workingCoordinate;


    #pragma mark - Apple Stores
workingCoordinate.latitude = 51.514298;
workingCoordinate.longitude = -73.973034;
iCodeBlogAnnotation *appleStore1 = [[iCodeBlogAnnotation alloc]     initWithCoordinate:workingCoordinate];
    [appleStore1 setTitle:@"Apple Store 5th Ave."];
[appleStore1 setSubtitle:@"Apple's Flagship Store"];
[appleStore1 setAnnotationType:iCodeBlogAnnotationTypeApple];

[viewController.mapView addAnnotation:appleStore1];

workingCoordinate.latitude = 51.514298;
workingCoordinate.longitude = -0.141949;
iCodeBlogAnnotation *appleStore2 = [[iCodeBlogAnnotation alloc] initWithCoordinate:workingCoordinate];
[appleStore2 setTitle:@"Apple Store St. Regent"];
[appleStore2 setSubtitle:@"London England"];
[appleStore2 setAnnotationType:iCodeBlogAnnotationTypeApple];

[viewController.mapView addAnnotation:appleStore2];



     }

如果您希望我发布任何额外的代码,我很乐意,但我不知道该在哪里查看,因此不知道发布哪些内容会有所帮助。

-杰夫

When I enable (uncomment) this line of code I get a SIGABRT crash - which is strange, to me, because I have never had this issue before.

cell.textLabel.text = [[annotations objectAtIndex:indexPath.row] title];

The error I get is:

2011-12-28 14:03:00.118 MapWithTableModalView-001[2006:11603] Localized name database is not present
2011-12-28 14:03:01.110 MapWithTableModalView-001[2006:11603] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

The project produces no errors or warnings.

The project is based on 2 UIViewControllers that slide on top of each other via a button - ModalViewContoller. When I press the button, the crash happens.

Just adding the code here - it is part of a tutorial, but I still want to get it:-) I know this does not look like an ordinary array, but the data is set like this in the project. Once I figure this out I want to set it in a Plist.

-(void)loadOurAnnotations
    {
CLLocationCoordinate2D workingCoordinate;


    #pragma mark - Apple Stores
workingCoordinate.latitude = 51.514298;
workingCoordinate.longitude = -73.973034;
iCodeBlogAnnotation *appleStore1 = [[iCodeBlogAnnotation alloc]     initWithCoordinate:workingCoordinate];
    [appleStore1 setTitle:@"Apple Store 5th Ave."];
[appleStore1 setSubtitle:@"Apple's Flagship Store"];
[appleStore1 setAnnotationType:iCodeBlogAnnotationTypeApple];

[viewController.mapView addAnnotation:appleStore1];

workingCoordinate.latitude = 51.514298;
workingCoordinate.longitude = -0.141949;
iCodeBlogAnnotation *appleStore2 = [[iCodeBlogAnnotation alloc] initWithCoordinate:workingCoordinate];
[appleStore2 setTitle:@"Apple Store St. Regent"];
[appleStore2 setSubtitle:@"London England"];
[appleStore2 setAnnotationType:iCodeBlogAnnotationTypeApple];

[viewController.mapView addAnnotation:appleStore2];



     }

If you would like me to post any additional code, I would be happy to, but I am not sure where to look anymore and hence don't really know which bit to post to be helpful.

-Jeff

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

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

发布评论

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

评论(1

回忆凄美了谁 2024-12-29 21:09:18

您的注释数组为空(有零个元素)。

查看您的 -loadOurAnnotations 方法,您似乎从未真正设置过您正在读取的 annotations 数组。尝试将该行更新为如下所示,看看是否有帮助:

// I'm not sure where viewController comes from but I'll assume it's a method on this
// class and that it's the same class that defines -loadOurAnnotations. If it's not,
// update this appropriately to get access to the mapView to which you've added
// the annotations
cell.textLabel.text = [[[[viewController mapView] annotations] objectAtIndex:indexPath.row] title];

Your annotations array is empty (has zero elements).

Looking at your -loadOurAnnotations method, you never actually seem to set the annotations array that you're reading. Try updating that line to something like below and see if that helps:

// I'm not sure where viewController comes from but I'll assume it's a method on this
// class and that it's the same class that defines -loadOurAnnotations. If it's not,
// update this appropriately to get access to the mapView to which you've added
// the annotations
cell.textLabel.text = [[[[viewController mapView] annotations] objectAtIndex:indexPath.row] title];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文