Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我点击地图时,它会在iOS5的初始时间崩溃吗? for(int i=0;i1){ latticudevalue=[[delarsInfoArray对象索引:i]valueForKey:@“纬度”]objectAtIndex:1]; longitudeValue=[[delarsInfoArray对象索引:i]valueForKey:@“经度”]对象索引:0]; } 其他的 { latticudevalue=@”; longitudeValue=@”; } CLLOCATIONCoordinated2D引脚定位; 如果(([latticudevalue floatValue]!=0)和([longitudeValue floatValue]!=0)){ mapRegion.center.latitude=[lattitudeValue浮点值]; mapRegion.center.longitude=[longitudeValue浮点值]; 如果(pinLocation.latitude!=0&&pinLocation.latitude!=0){ myAnnotation1=[[MyAnnotation alloc]init]; if([[delarsInfoArray objectAtIndex:i]计数]==0){ myAnnotation1.title=@; myAnnotation1.subtitle=@; } 其他的 { //NSLog(@“==========delears数组为==%@”,delarsInfoArray); NSLog(@“=======删除数组计数为%d”,[delarsInfoArray计数]; if([[delarsInfoArray objectAtIndex:i]valueForKey:@“Address”]objectAtIndex:2]!=nil) { myAnnotation1.title=[[delarsInfoArray对象索引:i]valueForKey:@“地址”]objectAtIndex:2]; } if([[delarsInfoArray objectAtIndex:i]valueForKey:@“城市”]objectAtIndex:3]!=nil){ myAnnotation1.subtitle=[[delarsInfoArray对象索引:i]valueForKey:@“城市”]对象索引:3]; } NSLog(@“%@”,[[delarsInfoArray对象索引:i]valueForKey:@“城市”]对象索引:3]); } [dealerMapView setRegion:mapRegion动画:是]; [dealerMapView添加注释:myAnnotation1]; myAnnotation1.coordinate=mapRegion.center; [myAnnotation1发布]; } } }_Ios_Objective C_Google Maps - Fatal编程技术网

当我点击地图时,它会在iOS5的初始时间崩溃吗? for(int i=0;i1){ latticudevalue=[[delarsInfoArray对象索引:i]valueForKey:@“纬度”]objectAtIndex:1]; longitudeValue=[[delarsInfoArray对象索引:i]valueForKey:@“经度”]对象索引:0]; } 其他的 { latticudevalue=@”; longitudeValue=@”; } CLLOCATIONCoordinated2D引脚定位; 如果(([latticudevalue floatValue]!=0)和([longitudeValue floatValue]!=0)){ mapRegion.center.latitude=[lattitudeValue浮点值]; mapRegion.center.longitude=[longitudeValue浮点值]; 如果(pinLocation.latitude!=0&&pinLocation.latitude!=0){ myAnnotation1=[[MyAnnotation alloc]init]; if([[delarsInfoArray objectAtIndex:i]计数]==0){ myAnnotation1.title=@; myAnnotation1.subtitle=@; } 其他的 { //NSLog(@“==========delears数组为==%@”,delarsInfoArray); NSLog(@“=======删除数组计数为%d”,[delarsInfoArray计数]; if([[delarsInfoArray objectAtIndex:i]valueForKey:@“Address”]objectAtIndex:2]!=nil) { myAnnotation1.title=[[delarsInfoArray对象索引:i]valueForKey:@“地址”]objectAtIndex:2]; } if([[delarsInfoArray objectAtIndex:i]valueForKey:@“城市”]objectAtIndex:3]!=nil){ myAnnotation1.subtitle=[[delarsInfoArray对象索引:i]valueForKey:@“城市”]对象索引:3]; } NSLog(@“%@”,[[delarsInfoArray对象索引:i]valueForKey:@“城市”]对象索引:3]); } [dealerMapView setRegion:mapRegion动画:是]; [dealerMapView添加注释:myAnnotation1]; myAnnotation1.coordinate=mapRegion.center; [myAnnotation1发布]; } } }

当我点击地图时,它会在iOS5的初始时间崩溃吗? for(int i=0;i1){ latticudevalue=[[delarsInfoArray对象索引:i]valueForKey:@“纬度”]objectAtIndex:1]; longitudeValue=[[delarsInfoArray对象索引:i]valueForKey:@“经度”]对象索引:0]; } 其他的 { latticudevalue=@”; longitudeValue=@”; } CLLOCATIONCoordinated2D引脚定位; 如果(([latticudevalue floatValue]!=0)和([longitudeValue floatValue]!=0)){ mapRegion.center.latitude=[lattitudeValue浮点值]; mapRegion.center.longitude=[longitudeValue浮点值]; 如果(pinLocation.latitude!=0&&pinLocation.latitude!=0){ myAnnotation1=[[MyAnnotation alloc]init]; if([[delarsInfoArray objectAtIndex:i]计数]==0){ myAnnotation1.title=@; myAnnotation1.subtitle=@; } 其他的 { //NSLog(@“==========delears数组为==%@”,delarsInfoArray); NSLog(@“=======删除数组计数为%d”,[delarsInfoArray计数]; if([[delarsInfoArray objectAtIndex:i]valueForKey:@“Address”]objectAtIndex:2]!=nil) { myAnnotation1.title=[[delarsInfoArray对象索引:i]valueForKey:@“地址”]objectAtIndex:2]; } if([[delarsInfoArray objectAtIndex:i]valueForKey:@“城市”]objectAtIndex:3]!=nil){ myAnnotation1.subtitle=[[delarsInfoArray对象索引:i]valueForKey:@“城市”]对象索引:3]; } NSLog(@“%@”,[[delarsInfoArray对象索引:i]valueForKey:@“城市”]对象索引:3]); } [dealerMapView setRegion:mapRegion动画:是]; [dealerMapView添加注释:myAnnotation1]; myAnnotation1.coordinate=mapRegion.center; [myAnnotation1发布]; } } },ios,objective-c,google-maps,Ios,Objective C,Google Maps,上面的代码将出现在视图中。在将地图加载到视图中后,当我单击地图时。应用程序崩溃。如何解决此崩溃?这里有很多问题,但跳到列表顶部的是以下几行: for (int i = 0; i< [delarsInfoArray count] ; i++) { NSString *lattitudeValue; NSString *longitudeValue; if ([[delarsInfoArray objectAtIndex:i]count]>1) {

上面的代码将出现在视图中。在将地图加载到视图中后,当我单击地图时。应用程序崩溃。如何解决此崩溃?

这里有很多问题,但跳到列表顶部的是以下几行:

for (int i = 0; i< [delarsInfoArray count] ; i++)
{
    NSString *lattitudeValue;
    NSString *longitudeValue;
    if ([[delarsInfoArray objectAtIndex:i]count]>1) {
        lattitudeValue = [[[delarsInfoArray objectAtIndex:i]valueForKey:@"LATITUDE"]objectAtIndex:1];
        longitudeValue = [[[delarsInfoArray objectAtIndex:i]valueForKey:@"LONGITUDE"]objectAtIndex:0];
    }
    else
    {
        lattitudeValue = @"";
        longitudeValue = @"";
    }
    CLLocationCoordinate2D pinLocation;
    if(([lattitudeValue floatValue] != 0) && ([longitudeValue floatValue] != 0) ) {
        mapRegion.center.latitude = [lattitudeValue floatValue];
        mapRegion.center.longitude = [longitudeValue floatValue];
        if(pinLocation.latitude !=0 && pinLocation.longitude !=0) {
            myAnnotation1 = [[MyAnnotation alloc] init];
            if ([[delarsInfoArray objectAtIndex:i] count] == 0) {

                myAnnotation1.title  = @"";
                myAnnotation1.subtitle = @"";
            }
            else
            {
                // NSLog(@"====== delears array is===%@",delarsInfoArray);
                NSLog(@"===== delears array count is %d",[delarsInfoArray count]);

                if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"Address"]objectAtIndex:2] !=nil)
                {
                    myAnnotation1.title = [[[delarsInfoArray objectAtIndex:i]valueForKey:@"Address"]objectAtIndex:2];
                }
                if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"City"]objectAtIndex:3]!= nil) {
                    myAnnotation1.subtitle = [[[delarsInfoArray objectAtIndex:i]valueForKey:@"City"]objectAtIndex:3];
                }

                NSLog(@"%@",[[[delarsInfoArray objectAtIndex:i]valueForKey:@"City"]objectAtIndex:3]);
            }

            [dealerMapView setRegion:mapRegion animated:YES];
            [dealerMapView addAnnotation:myAnnotation1];
            myAnnotation1.coordinate = mapRegion.center;
            [myAnnotation1 release];
        }
    }
}

问题是数组的
valueForKey
objectAtIndex
永远不会是
nil
。您不能在数组中存储
nil
,因此
valueForKey
所做的是,如果它找不到值,它将使用
NSNull
对象,
[NSNull null]
。表示找不到值,但使用
NSNull
(可以添加到数组中)而不是
nil
(不能)

问题可能是有一些后续代码(例如,试图计算调出编号气泡大小的代码)试图获取字符串的长度,但由于存储了
NSNull
,因此它试图调用
length
方法,但失败了

您可以通过多种方式解决此问题,例如:

if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"City"]objectAtIndex:3]!= nil) {
    ...

dealerMapView是通过(弱)IBoutlet连接的,或者是在ur代码中创建的??wt是控制台中的错误消息?@samfisher:IBoutlet MKMapView*dealerMapView;我通过xib@iPatel-[NSNull length]:无法识别的选择器发送到实例0x430cd8,我在控制台上收到此消息。我个人也倾向于建议使用一种简单的
delarsInfoArray
结构,但这是一种更广泛的对话。如果在 [DelaRunSnObjultObjtActudio:i] /<代码>中考虑每一个对象,那么这些对象中的每一个将是单个条目字典的数组,这是不必要的复杂、低效和脆弱的。我会把这些东西都做成字典。但我认识到,这会拖累您重新评估构建
delarsInfoArray
的代码,您可能不愿考虑这一点。
if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"City"]objectAtIndex:3]!= nil) {
    ...
if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"Address"]objectAtIndex:2] != [NSNull null])
    ...