2012-04-13 4 views
0

MKMapView에는 주소 좌표에 따라 몇 개의 핀이 있습니다. 모든 것이 제대로 작동 할 때까지지도보기를 언젠가 (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 메서드에서 전무로지도보기 대리자를 설정

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에서 충돌이 발생했으며 콘솔에서 지역에 대한 N 값이 공개되었습니다. SO의 7 가지 솔루션과 Apple DTS의 다양한 제안을 시도한 후, 나는 TatFits가 호출하는 region을 제거하여 해결했습니다. 나는 단순히 다음을 사용했다 :

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

[_mapView setRegion:adjustedRegion animated:YES]; 

분명히 그 regionThatFits 메소드에 문제가있다.

관련 문제