当我点击地图时,它会在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
结构,但这是一种更广泛的对话。如果在delarsInfoArray
的代码,您可能不愿考虑这一点。
if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"City"]objectAtIndex:3]!= nil) {
...
if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"Address"]objectAtIndex:2] != [NSNull null])
...