0
코어 데이터에서 일부 레코드를 가져 와서 테이블보기로 표시했습니다. 이 기록에는 모두 11 개의 속성이 있습니다. 이제 내 tableview 프레 젠 테이션에서 헤더에 이러한 모든 속성에 대한 버튼을 추가했습니다. 버튼을 클릭하면 해당 속성에 따라 레코드를 정렬하려고합니다. 정렬 설명자를 사용해 보았지만 작동하지 않습니다. 이 코드는 전혀 순서를 변경하지 않습니다,NSManaged 개체 배열 정렬
- (IBAction)sortButton:(id)sender {
// tags are from 100 to 111
UIButton *sortButton = (UIButton*)sender;
NSString *sortDescriptorKey = nil;
// create sort descriptor key according to the tag value
if (sortButton.tag == 100) sortDescriptorKey = [NSString stringWithString:@"reportID "];
....
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortDescriptorKey ascending:YES];
[self.recordArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
[self.tableView reloadData];
}
하지만 - : 내 코드는 다음과 같다. 누락 된 항목이 있거나 다른 방법이 있습니다.
감사합니다, 어리석은 실수 :) – cocoaNoob