2010-04-16 49 views
0

我需要显示我从解析器中得到的名称列表。我正在获取NSMutable列表,然后我需要按字母顺序显示它们。如何在Objective-C中按字母顺序排序NSMutableArray名称列表?

我试图做的是给定为:

NSArray *myArtistArray=[[NSArray alloc]init]; 
myArtistArray=[artistsList sortUsingSelector:@selector(compare:) ]; 

// error void value not ignored as it outght to be 
[myArtistArray sortedArrayUsingSelector:@selector(compare:)]; 

回答

8
[yourMutableArray sortUsingSelector:@selector(compare:)]; 
[yourArray sortedArrayUsingSelector:@selector(compare:)]; 
+0

我得到了错误的错误空值并不像outght是我如何能得到排序时忽略list – 2010-04-16 07:04:03

+0

'sortUsingSelector'对可变数组进行排序并且不返回值。 'sortedArrayUsingSelector'创建并返回数组的排序副本。 – drawnonward 2010-04-16 17:22:32

4
[yourMutableArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 
2
NSArray *arraysort=[[NSArray alloc] initWithObjects:@"z",@"v",@"a",@"g",@"b", nil]; 
NSArray *sortedArray = [arraysort sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 
    for (NSString *str in sortedArray) { 
     NSLog(@"string %@ ",str); 
    } 
    NSLog(@"sortedarrayelements %d",[sortedArray count]); 
2
[yourArrayName sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];