ios - sorting a list of names in Xcode -


i got table view controller imports nsobject nsstrings. in table view controller create list, not in alphabetical order. here pieces of code using:

songs.h:

#import <foundation/foundation.h>  @interface songs : nsobject @property (nonatomic, retain) nsstring* name; @property (nonatomic, retain) nsstring* description; @property (assign) int serial;  -(id) initwithname:(nsstring*) songname anddescription:(nsstring*)thedescription;  @end 

songs.m:

#import "songs.h"  @implementation songs @synthesize name; @synthesize description; @synthesize serial;  -(id) initwithname:(nsstring *)thename anddescription:(nsstring *)thedescription {     self = [super init];     if(self)     {         self.name = thename;         self.description = thedescription;     }     return self; } @end 

and tableview:

#import "tableviewcontroller.h" #import "detailviewcontroller.h" #import "songs.h"  @implementation tableviewcontroller  @synthesize alltabledata; @synthesize filteredtabledata; @synthesize letters; @synthesize searchbar; @synthesize isfiltered;  nsarray *songsindextitles;     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:@"ağlarsa 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:@"neredesin sen?" 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 "], 

and list goes on , on. sectioning works great not figure out how make song names in each section in alphabetical order; in section should 1-ahu gozlum 2-aglarsa anam aglar 3- aynali kemer....

any appreciated.

use nssortdescriptor. ensure alltabledata nsmutablearray:

nssortdescriptor *desc = [nssortdescriptor sortdescriptorwithkey:@"name"                                                        ascending:yes]; [alltabledata sortusingdescriptors:@[ desc ]]; 

then reload tableview.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -