2012-04-13 12 views
0

MKMapViewにいくつかのピンをロードしていますが、これはアドレスの座標に基づいて低下します。すべてがうまく動作するまで、私はいつもmapviewを開いたままにしています(2分)。実際に起こったイベントはなく、クラッシュします。これの理由は何でしょうか。私のviewDidLoadでMapVIewのクラッシュ

私は次のコード

mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    mapView.delegate=self; 

    [self.view addSubview:mapView]; 

    addressbook = ABAddressBookCreate(); 
    for (i = 0; i<[groupContentArray count]; i++) { 
     NSLog(@"group content array %@", groupContentArray); 
     person = ABAddressBookGetPersonWithRecordID(addressbook,[[groupContentArray objectAtIndex:i] intValue]); 
     NSLog(@"Person %@", person); 
     ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty); 
     NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty); 
     NSLog(@"Address %@", address); 
     for (NSDictionary *addressDict in address) 
     { 
      addAnnotation = nil; 
      firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 
      lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

      NSString *country = [addressDict objectForKey:@"Country"]; 
      NSString *streetName = [addressDict objectForKey:@"Street"]; 
      NSString *cityName = [addressDict objectForKey:@"City"]; 
      NSString *stateName = [addressDict objectForKey:@"State"]; 

      if (streetName == (id)[NSNull null] || streetName.length == 0) streetName = @""; 
      if (stateName == (id)[NSNull null] || stateName.length == 0) stateName = @""; 
      if (cityName == (id)[NSNull null] || cityName.length == 0) cityName = @""; 
      if (country == (id)[NSNull null] || country.length == 0) country = @""; 


      NSString *fullAddress = [streetName stringByAppendingFormat:@"/%@/%@/%@", cityName, stateName, country]; 
      mapCenter = [self getLocationFromAddressString:fullAddress]; 
      if(stateName != NULL || country != NULL || streetName != NULL || cityName != NULL){ 

       if ((mapCenter.latitude == 0) && (mapCenter.longitude == 0)) 
       { 
        //Alert View      
       } 
       else{ 

       if(addAnnotation == nil){ 
        addAnnotation = [[[MyAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:[groupContentArray objectAtIndex:i] ]autorelease]; 

        [mapView addAnnotation:addAnnotation];} 
       else{ 
        //  ALert View     

       } 
       } 
      } 
     } 
     CFRelease(addressProperty); 

    } 
    [self zoomToFitMapAnnotations:mapView]; 


    [self.navigationItem setHidesBackButton:YES animated:YES]; 
    NSString *mapTitle = localizedString(@"MAP_TITLE"); 
    [self setTitle:mapTitle]; 
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 
+3

クラッシュやいくつかのコード行に関連したエラーを投稿できますか? – simonbs

+0

いくつかのコードとエラースクリーンショットを投稿すると、私たちがあなたを助けるのに役立ちます。 :-) –

+0

あなたのコードをデバッグしようとすると、ここにいくつかのコードを投稿して他の人があなたに答えて返すようにしてください。 –

答えて

0

私の問題を解決しました。

1

これを試してみてください書き込み: - (無効)のviewDidLoad { を[スーパーのviewDidLoad]; deallocメソッドでnilにMapViewのデリゲートを設定

UIImageView *topBar = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header1.png"]]; 
topBar.frame = CGRectMake(0, 0, 320, 44); 
[self.navigationController.navigationBar insertSubview:topBar atIndex:0]; 
[topBar release]; 

self.navigationController.navigationBarHidden=YES; 

[mapView setMapType:MKMapTypeStandard]; 
[mapView setZoomEnabled:YES]; 
[mapView setScrollEnabled:YES]; 
[mapView setShowsUserLocation:YES]; 
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
region.center.latitude = [strLat doubleValue]; 
region.center.longitude = [strLong doubleValue]; 
region.span.longitudeDelta = 0.01f; 
region.span.latitudeDelta = 0.01f; 
[mapView setRegion:region animated:YES]; 

[mapView setDelegate:self]; 

mapAnonotationView *ann = [[mapAnonotationView alloc] init]; 
ann.title = name; 
ann.subtitle = Address; 
ann.coordinate = region.center; 
[mapView addAnnotation:ann]; 
[ann release]; 
ann = nil; 

}

+0

彼の実装がどのように見えるかわからない場合、これはどのようにして正確に質問に答えますか? – CodaFi

0

私のiPhone4Sでクラッシュしていて、コンソールが地域のナノ値を明らかにしました。 SOからの7種類のソリューションやApple DTSのさまざまな提案を試した後、私はregionThatFitsが呼び出すことを排除して解決しました。私は単に使用:

CLLocationDistance visibleDistance = 100000; // 100 kilometers 
MKCoordinateRegion adjustedRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, visibleDistance, visibleDistance); 

[_mapView setRegion:adjustedRegion animated:YES]; 

はどうやらそのregionThatFits方法に問題があります。