简体   繁体   中英

index and section issue in tableview

i got a tableview controller. in the table view i have huge list of scrambled names. sectioning works well, it groups all the names according to the first letter of the name however the table view lists the names in the order of the written code in Xcode. here is the piece of code i use:

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 "],

...

it goes on and on. what i need to do is to list "Adin Ne" prior to "Aglarsa Anam Aglar" automatically. like i said sectioning works perfect, but listing is no good.

would appreciate any help, thanks

why don't you just sort allTableData using sortedArrayUsingComparator of NSArray.

Sort it using [string1 compare:string2 options:NSNumericSearch]; inside block of sortedArrayUsingComparator

Then use it as Datasource of Table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM