0

열 헤더를 클릭하여 정렬 할 수있는 데이터 목록이 있습니다. 조치를 정렬이 기본 해결하기 위해 어떤 방법이 있나요NSTableView에서 정렬 순서

1A 
2A 
3A 
4A 
5A 
6A 
7A 
8A 
9A 
10A 
11A 

etc... 

:

10A 
11A 
12A 
1A 
2A 
3A 

etc... 

이상적으로, 나는 그것이 같은 정렬하고 싶습니다 : 유일한 문제는이 같은 표시이다?

Sort Descriptors Properties

@Monolo :

이러한 내 정렬 디스크립터의 속성입니다 일반적으로

self.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"self" 
                 ascending:YES 
                 comparator:^NSComparisonResult(id obj1, id obj2) { 
                  NSLog(@"COMPARATOR!"); 
                  return [obj1 compare:obj2 
                     options:NSNumericSearch]; 
                 }]]; 
+0

http://stackoverflow.com/questions/8242735/how-to-sort-array-controller-alphabetically-with-numbers-last-in-objective-c –

답변

0

enter image description here, 당신을 정렬의 종류를 통해 얻을 수를 찾고 있습니다 compare:options: 메서드가 NSString이므로 코드에서 정렬 설명자를 생성하는 경우 (프로그래밍 방식으로 또는 nib 파일에서 바인딩하여) 배열 컨트롤러로 가져 오면 원하는 것을 얻을 수 있습니다.

은 다음과 같이 예를 들어, 정렬 설명 배열을 설정합니다

// AppDelegate.h: 

@property (strong) NSArray *sortDescriptors; 


//AppDelegate.m: 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 
    self.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"self" 
               ascending:YES 
               comparator:^NSComparisonResult(id obj1, id obj2) { 
                return [obj1 compare:obj2 
                   options:NSNumericSearch]; 
               }]]; 
} 

그래서 그 대신 표준 사용자 기본 컨트롤러와 결합, 당신이 당신의 응용 프로그램 위임 (또는 당신이 선호하는 다른 객체에 결합한다 이 도우미 객체들을 보유), 당신은 당신이 행한 행동을 얻습니다. 위 코드 스 니펫을 사용하여 바인딩의 모델 키 경로는 sortDescriptors입니다.

+0

테이블에 대한 정렬 설명자를 변경합니까? 어레이 컨트롤러? –

+0

해당 코드를 사용하면 예기치 않은 결과가 발생합니다. 원본 게시물을 편집하여 sceenshot을 포함 시켰습니다. –

+0

NSLog 문이 호출되지 않았지만 appdidfinishlaunching 함수가 있는지 확인할 수 있습니다. 이것은 NSLog in (질문에 추가) 코드입니다. –