为什么这会产生错误——幽灵 NSArray?
当我启用(取消注释)这行代码时,我遇到了 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的注释数组为空(有零个元素)。
查看您的
-loadOurAnnotations
方法,您似乎从未真正设置过您正在读取的annotations
数组。尝试将该行更新为如下所示,看看是否有帮助:Your annotations array is empty (has zero elements).
Looking at your
-loadOurAnnotations
method, you never actually seem to set theannotations
array that you're reading. Try updating that line to something like below and see if that helps: