2010-11-29 56 views
2
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:globalManagedObjectContext]; 
    [fetchRequest setEntity:entity]; 
    NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES]; 
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]]; 
    fetchResults = [NSMutableArray arrayWithArray:[globalManagedObjectContext executeFetchRequest:fetchRequest error:nil]]; 
    [fetchRequest release]; 
    [sortByName release]; 
    return fetchResults; 

遵循大小寫敏感。大寫字母在上面。數據分類

Ab 
Ba 
a. 

像上面那樣。請給出任何解決方案忽略大小寫

回答

5

使用

NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES selector:@selector(caseInsensitiveCompare:)]; 
-1

NSSortDescriptor * authorDescriptor = [[NSSortDescriptor頁頭​​] initWithKey:@ 「作者」 上升:YES];