2012-08-09 56 views
0

我的Iphone App中有一个sqlite数据库。我有一个表名,需要在tableView中使用sectionIndexTitlesForTableView时进行排序。Sqlite:用特殊字符排序danishæø

sql语句是“SELECT * FROM buildings ORDER BY name ASC”。这给出了排序的结果,但不知何故排序失败的特殊字符 - 丹麦æøå。 像:

  • 奥胡斯Universitet
  • 奥胡斯埃
  • OER海上Ferieby

埃应该来Ø后。

我曾试着在COLLATE上读过,但在这里做什么时感觉非常无知。请注意,sqlite似乎工作正常 - 使用UTF8编码,万物在应用程序中看起来很好。除了字母顺序。

任何线索? -

回答

0

因为我只需要在sectionForSectionIndexTitle使用的阵列正确排序表视图的数据源我做绕过SQLite中的排序问题:


NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"da_DK"]; sections = [sections sortedArrayUsingComparator:^(NSDictionary *first, NSDictionary *second) { NSString *str1 = [first objectForKey:@"section"]; NSString *str2 = [second objectForKey:@"section"];

return [str1 compare:str2 
        options:0 
        range:NSMakeRange(0, [str1 length]) 
        locale:locale]; 

}];
我认为其确定要做到这一点,因为数部分数组中的条目数不会超过字母表中的字符数。