Thursday 6 December 2012

Sort Arr_title and Arr_address According to sorted Arr_distance

Sample code Here ......................

// Put the two arrays into a dictionary as keys and values
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:secondArray forKeys:firstArray];
// Sort the first array
NSArray *sortedFirstArray = [[dictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
// Sort the second array based on the sorted first array
NSArray *sortedSecondArray = [dictionary objectsForKeys:sortedFirstArray notFoundMarker:[NSNull null]];

I am get success to sort array using index of another array see following methods ..............

I have three  arrays    Arr_title ,Arr_distance,Arr_address

i m sorting Arr_distance as

NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"self"    ascending:YES]autorelease];
                                                    
 sortedFloats = [appDel.Arr_distance sortedArrayUsingDescriptors: 
 [NSArray arrayWithObject:sortDescriptor]];
       


Now Sort Arr_title and Arr_address Using Following Method


// Put the two arrays into a dictionary as keys and values
    NSDictionary *dictTitle = [NSDictionary dictionaryWithObjects:Arr_title   forKeys:appDel.Arr_distance];
   
    // Sort the second array based on the sorted first array
    NSArray *sortedTitle = [dictTitle objectsForKeys:sortedFloats notFoundMarker:[NSNull null]];
   
   
    NSLog(@" Sorted Title : %@",sortedTitle);

  
    // Put the two arrays into a dictionary as keys and values
    NSDictionary *dictAddress = [NSDictionary dictionaryWithObjects:Arr_address   forKeys:appDel.Arr_distance];
   
    // Sort the second array based on the sorted first array
    NSArray *sortedAddress = [dictAddress objectsForKeys:sortedFloats notFoundMarker:[NSNull null]];
   
   
    NSLog(@" Sorted Title : %@",sortedAddress);

No comments:

Post a Comment