MKMapview 在初始化时崩溃 - 显示陌生人错误 - Objective-c

MKMapview Crashing on Initialization - Showing stranger error - Objective-c

我正在代码中添加 MKMapview。它在初始化时崩溃。错误非常奇怪,我不明白为什么会这样。

我也添加了 Mapkit 框架。这是代码

    NSString *lat = @"30.733315";
    NSString *lon = @" 76.779419";


    MKMapView   *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 205)];
    mapView.mapType = MKMapTypeStandard;
    mapView.delegate = self;
    mapView.zoomEnabled=NO;
    mapView.userInteractionEnabled=YES;
    // [mapView setCenterCoordinate:CLLocationCoordinate2DMake(40.7326808, -73.9843407) animated:NO];
    mapView.scrollEnabled=NO;
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake([lat floatValue], [lon floatValue]), 500, 500);
    MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
    [mapView setRegion:adjustedRegion animated:NO];
    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
    annotation.coordinate= CLLocationCoordinate2DMake([lat floatValue], [lon floatValue]);
    annotation.title=@"qadsa";
    [mapView addAnnotation: annotation];
    [mapView selectAnnotation:annotation animated:YES];
    [self.view addSubview:mapView];

我遇到的错误是:

2017-10-01 21:13:15.200959+0530 map[45012:6213684] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1860e3d38 0x1855f8528 0x18607cc44 0x186069e34 0x18bd11514 0x18bd10c28 0x18bd100ac 0x18bd11c8c 0x18bd11cb4 0x18bd84f28 0x18bd86a48 0x104c2545c 0x104c2617c 0x18bd86a18 0x18bf24350 0x104c375cc 0x104c2545c 0x104c34110 0x104c289a4 0x104c35104 0x104c3c100 0x185d0efe0 0x185d0ec30)
libc++abi.dylib: terminating with uncaught exception of type NSException

感谢大家检查问题并建议我回答。

这是由于字符串的本地化。我正在制作多语言应用程序。它因本地化文件(西班牙语)中的错误字符串而崩溃。删除本地化后,应用程序开始工作。所以我再次重写了整个本地化文件并修复了错误。现在地图工作正常。

所以错误是由于文件的本地化。主要障碍是 Xcode 没有显示任何本地化文件错误。它显示奇怪的错误。