整理数据
获取汉字拼音的首字母
/*
*获取汉字拼音的首字母, 返回的字母是大写形式, 例如: @"俺妹", 返回 @"A".
*如果字符串开头不是汉字, 而是字母, 则直接返回该字母, 例如: @"b美女", 返回 @"B".
*如果字符串开头不是汉字和字母, 则直接返回 @"#", 例如: @"&哈哈", 返回 @"#".
*字符串开头有特殊字符(空格,换行)不影响判定, 例如@" a啦啦啦", 返回 @"A".
*/
- (NSString *)getFirstLetter {
NSString *words = [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (words.length == 0) {
return nil;
}
NSString *result = nil;
unichar firstLetter = [words characterAtIndex:0];
int index = firstLetter - HANZI_START;
if (index >= 0 && index = 'a' && firstLetter = 'A' && firstLetter String? {
return (self.firstLitterArray[section]["firstLetter"] as! String)
}
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
var title : [String] = []
for i in 0 .. Int {
if title == UITableView.indexSearch {
return NSNotFound
}
return UILocalizedIndexedCollation.current().section(forSectionIndexTitle: index)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
效果展示
完整示例
Swift之UITableView新增“索引”数组快速定位查找数据 文章来源: blog.csdn.net,作者:Serendipity·y,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/Forever_wj/article/details/108210211
|