2012-05-05 85 views
0

我在排序包含NSString包含int的NSMUtableArray中有一個小問題。 我的排序是這樣排序包含字符串forrmat中的數字的NSMutableArray

scoreString=[NSString stringWithFormat:@"%lld",GameScore]; 
    [scorearr addObject:scoreString]; 
    NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO]; 
    NSArray *scoreArray= [scorearr sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]]; 
    scorearr =(NSMutableArray *)ary; 
+0

是不是排序? – vishiphone

回答

0

好吧,我正在完成與此,

NSNumber *inrank=[NSNumber numberWithInt:GameScore]; 
    scoreString=[NSString stringWithFormat:@"%lld",GameScore]; 
    [scorearr addObject:inrank]; 
    NSLog(@"%@",scorearr.description); 
    //sorting array 
    sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 
    NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO]; 
    NSArray *scoreArray= [scorearr sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]]; 
    scorearr =(NSMutableArray *)scoreArray; 
    NSLog(@"%@",scoreArray.description); 
1

您使用的可變數組所以最好寫

NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO]; 
[scorearr sortUsingDescriptors:[NSArray arrayWithObject: sortOrder]]; 

這樣你排序時不會創建新的數組。

相關問題