2012-02-03 5 views
2

NSArray에 사전 순으로 정렬하고 현재 sortedArrayUsingSelector:@selector (localizedCaseInsensitiveCompare:)을 사용하고 있습니다. 이것은먼저 NSArray 정렬 문제가 정렬되어 있습니다.

CAA 
CBL 
CCC 
Cab 
Car 
Cat 

약어를 먼저 알파벳 순으로 정렬 한 다음 다른 문자 순으로 정렬합니다. 두문자가 정규 단어와 함께 정렬되도록 정렬하려면 무엇을 사용해야합니까? 애플의 문서에서 답을 찾지 못하는 것 같습니다.

book = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

답변

0

당신은

- (NSArray *)sortedArrayUsingComparator:(NSComparator)cmptr 

를 사용하여 원하는 동작을 위해 NSComparator을 만들 수 있습니다. 이처럼

:

NSarray *sortedArray = [myArray sortedArrayUsingComparator:^(id obj1, id obj2) { 
    //Decide in the order 
    if (yourCondition) 
    { 
    return NSOrderedSame 
    } 
}]; 
+0

감사 오스카. 당신은 정교 할 수 있습니까? 내 전체 코드는'book = [[self.sections valueForKey : [[self.sections allKeys] sortedArrayUsingSelector : @selector (localizedCaseInsensitiveCompare :)] objectAtIndex : indexPath.section]] objectAtIndex : indexPath.row]; ' – awDemo

+0

편집 해 주셔서 감사합니다. 당신의 대답은 ... 나는 NSComparator를 사용한 적이 없기 때문에 이것을 작동 시켜서 작동하는지 확인해야합니다. 내가 알려 주마. 두문자어가 왜 먼저 묶여 있는지는 나에게 놀라운 일이다 ... – awDemo

관련 문제