【发布时间】:2011-12-04 09:27:29
【问题描述】:
我想知道如何为从 iphone (xcode 4.2) 中的 sqlite 数据库中提取的名称创建一个字母组部分。我能够为名字做组部分,但不能做姓氏部分。有些名字有小写我希望标题字母全部大写,包括这些名字的小写和大写字母。有些名字有 3 个名字,想确保我得到姓氏。我的代码在下面,它似乎混淆了字母表(从 A 到 L 到 C 到 D)以及 e 和 E(我不想显示的上下)
//---创建索引---
nameIndex = [[NSMutableArray alloc] init];
for (int i=0; i<[_authorsInfo count]-1; i++){ //---get the first char of each state--- authors *tempAuthor = [_authorsInfo objectAtIndex:i]; char alphabet = [tempAuthor.name characterAtIndex:0]; NSString *uniChar = [NSString stringWithFormat:@"%C", alphabet]; //---add each letter to the index array--- if (![nameIndex containsObject:uniChar]) { [nameIndex addObject:uniChar]; }
更新*
self.authorsInfo = [诗歌数据库].authorsInfo;
//---create the index--- nameIndex = [[NSMutableArray alloc] init]; for (int i=0; i<[_authorsInfo count]-1; i++){ //---get the first char of each state--- authors *tempAuthor = [_authorsInfo objectAtIndex:i]; NSArray *nameComponents = [tempAuthor.name componentsSeparatedByString:@" "]; NSString *lastName = [ nameComponents objectAtIndex: nameComponents.count-1 ]; char alphabet = [lastName characterAtIndex:0]; //char alphabet = [tempAuthor.name characterAtIndex:0]; NSString *uniChar = [NSString stringWithFormat:@"%C", alphabet]; //---add each letter to the index array--- if (![nameIndex containsObject:uniChar]) { [nameIndex addObject:uniChar]; } }
【问题讨论】:
标签: iphone ios header tableview