iphone如何使用sqlite获取组部分tableview的姓氏首字母?
我想知道如何为从 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++){ //---获取每个状态的第一个字符--- 作者 *tempAuthor = [_authorsInfo objectAtIndex:i]; char 字母 = [tempAuthor.name characterAtIndex:0]; NSString *uniChar = [NSString stringWithFormat:@"%C", 字母表]; //---将每个字母添加到索引数组--- if (![nameIndex containsObject:uniChar]) { [nameIndex addObject:uniChar]; }
更新*
self.authorsInfo = [诗歌数据库].authorsInfo;
//---创建索引--- nameIndex = [[NSMutableArray alloc] init]; for (int i=0; i<[_authorsInfo count]-1; i++){ //---获取每个状态的第一个字符--- 作者 *tempAuthor = [_authorsInfo objectAtIndex:i]; NSArray *nameComponents = [tempAuthor.name elementsSeparatedByString:@" "]; NSString *lastName = [ nameComponents objectAtIndex: nameComponents.count-1 ]; char 字母表 = [姓氏字符索引:0]; //char 字母 = [tempAuthor.name characterAtIndex:0]; NSString *uniChar = [NSString stringWithFormat:@"%C", 字母表]; //---将每个字母添加到索引数组--- if (![nameIndex containsObject:uniChar]) { [nameIndex addObject:uniChar]; } }
I would like to know how to make a alphabet group sections for the names extracted from sqlite database in iphone (xcode 4.2). I was able to do group section for first name but was unable to do the last name part. Some name have lowercase I want the headers letter to have all capital which includes the lower and uppercase letters of those names. Some names have 3 names and wanted to make sure i get the last name. My code is below and it seems to mix up the alphabet (from A to L to C to D) and also e and E (lower and upper which i dont want to display)
//---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]; 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]; }
UPDATE*
self.authorsInfo = [poemDatabase database].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]; } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
tempAuthor.name
包含带有空格的完整名称,请尝试以下操作:If
tempAuthor.name
contains whole name with spaces try this: