tableview中的索引和节问题

时间:2015-07-06 07:20:23

标签: ios objective-c list uitableview indexing

我有一个tableview控制器。在表格视图中,我有大量的乱序名称。分割效果很好,它根据名称的第一个字母对所有名称进行分组,但表格视图按照Xcode中编写代码的顺序列出名称。这是我使用的代码片段:

SongsIndexTitles = @[@"A", @"B", @"C",@"Ç", @"D", @"E", @"F", @"G", @"H", @"I",@"İ", @"J", @"K", @"L", @"M", @"N", @"O", @"Ö", @"P", @"R", @"S",@"Ş", @"T", @"U",@"Ü", @"V", @"Y", @"Z"];


allTableData = [[NSArray alloc] initWithObjects:
                [[Songs alloc] initWithName:@"Aglarsa Anam Ağlar" andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Aynalı Kemer" andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Boşuna " andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Çöpçüler " andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Ahu Gozlum" andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Hepsi Senin mi?" andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Adin Ne" andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Pamuk" andDescription:@"Seslendiren: Abidin"],
                [[Songs alloc] initWithName:@"Sen Yoluna Ben Yoluma" andDescription:@"Seslendiren: Abidin "],
                [[Songs alloc] initWithName:@"Yolcu Yolunda Gerek" andDescription:@"Seslendiren: Abidin "],

...

它一直在继续。我需要做的是自动在“Aglarsa Anam Aglar”之前列出“Adin Ne”。就像我说切片工作完美,但上市并不好。

非常感谢任何帮助,谢谢

1 个答案:

答案 0 :(得分:0)

为什么不使用NSArray的sortedArrayUsingComparator对allTableData进行排序。

使用[string1 compare:string2 options:NSNumericSearch];

块内的sortedArrayUsingComparator对其进行排序

然后将其用作表的数据源。