2011-05-03 7 views
0

사용자에게 가장 가까운 거리별로 장소의 tableView를 정렬하고 싶습니다. 세 가지 방법 (myLocation, clubLocation 및 enumerate)이 있습니다. lat 및 long은 plist (아래 코드의 objectatIndex 4 및 5)에서 유지됩니다. 나는 두 개의 배열을 만들었습니다. 하나는 lat에, 하나는 열거 메서드에서 만들어졌지만, 모든 것을 함께 연결하는 방법에 대한 정신적 블록이 있습니다. 열거 형 배열을 대신 void (그냥 자리 표시 자) 반환 할 것이라고 가정합니다. 한 번에 두 개의 배열을 반환 할 수 있습니까? 나는 위도와 영원을 위해 한 번 열거합니까? 도와주세요.Plist에서 위도와 경도를 열거하십시오.

Lat에 대한 두 가지 방법과 Long에 대한 방법 두 가지를 업데이트했습니다. 어떻게 거리와 관련 객체를 반환합니까? 예를 들어, 어떤 거리가 어떤 위치와 관련되어 있는지를 알아야하기 때문에 단지 거리의 배열은 좋지 않습니다.

  • 하여 1 개 이상의 값을 반환

    -(NSArray *)distanceFromLat 
    { 
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Data3" ofType:@"plist"]; 
        NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 
    
        NSMutableArray *latitudeArray = [[NSMutableArray alloc] init]; 
        latitudeArray = [[tempDictionary objectForKey:@"Subtree"]objectAtIndex:4]; 
    
        NSEnumerator *enumLat = [latitudeArray objectEnumerator]; 
        id object; 
    
        while ((object = [enumLat nextObject])) { 
         [myLocation distanceFromLocation:clubLocation]; 
        } 
    
    } 
    
    -(NSArray *)distanceFromLong 
    { 
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Data3" ofType:@"plist"]; 
        NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 
    
        NSMutableArray *longitudeArray = [[NSMutableArray alloc] init]; 
        longitudeArray = [[tempDictionary objectForKey:@"Subtree"]objectAtIndex:5]; 
        NSEnumerator *enumLong = [longitudeArray objectEnumerator]; 
        id object; 
    
        while ((object = [enumLong nextObject])) { 
         [myLocation distanceFromLocation:clubLocation]; 
        } 
    
    } 
    
        -(CLLocation *)clubLocation 
        { 
         NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Data3" ofType:@"plist"]]; 
         NSArray *array = [dictionary objectForKey:@"Subtree"]; 
         NSNumber *latitude = [NSString stringWithFormat:@"%@",[array objectAtIndex:4]]; 
         NSNumber *longitude = [NSString stringWithFormat:@"%@",[array objectAtIndex:5]]; 
         double clubLatitude = [latitude doubleValue]; 
         double clubLongitude = [longitude doubleValue]; 
         clubLocation = [[CLLocation alloc]initWithLatitude:clubLatitude longitude:clubLongitude]; 
         return clubLocation; 
    
        } 
    
        -(CLLocation *)myLocation 
        { 
         CLLocation *location = [locationManager location]; 
         CLLocationCoordinate2D coordinate = [location coordinate]; 
         NSNumber *myLatitude = [NSNumber numberWithDouble:coordinate.latitude]; 
         NSNumber *myLongitude = [NSNumber numberWithDouble:coordinate.longitude]; 
         double myLatitudeD = [myLatitude doubleValue]; 
         double myLongitudeD = [myLongitude doubleValue]; 
         myLocation = [[CLLocation alloc]initWithLatitude:myLatitudeD longitude:myLongitudeD]; 
         return myLocation; 
        } 
    
  • 답변

    0

    (구조체 쌍 {; 제 번호 제 이드}) 맞춤 구조체를 이용하여 적어도 세 가지 간단한 방법

    1. 에서 수행 될 수있다 두 객체를 모두 포함하는 nsarray

    2. 변수로 포인터를 변수로 사용 (enumerationWithFirst : (NSArray * ) 첫 번째 초 : (NSArray *) 두 번째

    Objective-C++를 사용하면 몇 가지 옵션이 추가되지만 이러한 옵션은 추가해야합니다.

    그런데 두 개의 "열거 자"방법을 사용하는 것이 더 합리적입니다. 기본적으로 간단한 데이터 구조에서 속성을 반환합니다.

    아, 코드 누출 여부를 확인하십시오. 내가 틀리지 않으면 몇 가지가있다.

    +0

    나는 두 가지 새로운 방법으로 질문을 업데이트했는데, 이것들을 볼 수 있습니까? 또한 메모리 누수가 있다는 것을 알고 있으며 아직 처리하지 않았습니다. 감사합니다. – Eric

    +0

    누군가가 나를 도울 수 있다면 나는 여전히 내가 업데이트 한 코드에 대한 도움이 필요합니다. – Eric

    관련 문제