2013-03-23 18 views
2
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]; 
     } 
    } 
} 

上面的代碼寫在viewWillAppear.After加載映射到視圖中,當我點擊map.app獲取崩潰。如何解決這個崩潰?當我點擊地圖時,它在iOS5的初始時間崩潰了?

+0

dealerMapView經由(弱)IBOutlet中附接或它在我們的代碼創建?? – samfisher 2013-03-23 11:07:23

+0

wt是控制檯中的錯誤消息? – iPatel 2013-03-23 11:08:49

+0

@samfisher:IBOutlet MKMapView * dealerMapView;我通過xib連接 – Pavne 2013-03-23 11:39:57

回答

2

這裏有很多的問題,而是躍起出到列表頂部的一個是讀線:

if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"Address"]objectAtIndex:2] !=nil) 
    ... 

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

的問題是,objectAtIndexvalueForKey的一個數組將從不nil。您不能將nil存儲在數組中,因此如果valueForKey沒有找到值,它會使用NSNull對象[NSNull null]。這表明沒有找到值,但使用NSNull(可以將其添加到數組中)而不是nil(不能)。

問題很可能是有一些後續代碼(例如,試圖計算出標註泡泡大小的代碼)試圖獲取字符串的長度,但由於您存儲了NSNull,它是試圖調用length方法並且失敗。

你能解決這個多種方式,如:

if ([[[delarsInfoArray objectAtIndex:i]valueForKey:@"Address"]objectAtIndex:2] != [NSNull null]) 
    ... 
+1

謝謝我使用你的解決方案解決了這個問題.. – Pavne 2013-03-23 13:40:08

相關問題