【发布时间】:2010-11-18 08:55:28
【问题描述】:
我正在将普通的 tableview 转换为分段的 tableview。我希望节标题是节中项目的第一个字母。
这是我目前在 titleForHeaderInSection 方法中的内容:
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"Name"
ascending:YES] autorelease];
NSArray *sortedArray;
NSMutableArray *commonNameArray = [tableDataSource valueForKey:@"Name"];
NSArray *uniquearray;
uniquearray = [[NSSet setWithArray:commonNameArray] allObjects];
sortedArray = [uniquearray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
此代码删除重复的标题并按字母顺序对列表进行排序。现在我只需要将数组中的字符串转换为第一个字母。解决此问题的最佳方法是什么?
【问题讨论】:
标签: iphone arrays uitableview sorting