2010-09-21 42 views
0

我存儲解析的XML值作爲可變數組一些這樣的事全局數據...排序全局數據alphbetically

.h文件中

@interface GlobalData : NSObject { 

NSMutableArray *array; 

}

@屬性(非原子,保留)NSMutableArray *數組;

  • (id)sharedData;

在.m文件

static GlobalData *sharedGlobalData = nil; 

@implementation全球國際

@synthesize陣列;

+(ID)sharedData {

@synchronized(self) { 
    if(sharedGlobalData == nil) 
    { 
     sharedGlobalData=[[GlobalData alloc] init]; 
     sharedGlobalData.boats=[[NSMutableArray alloc] init]; 

    } 
} 
return sharedGlobalData; 

}

  • (ID)allocWithZone:(NSZone *)區{ @synchronized(個體){ 如果(sharedGlobalData ==無) SharedGlobalData = [super allocWithZone:zone]; [0124] return sharedGlobalData; } } return nil; }

我將數組的值傳遞給表視圖並將其顯示爲表。現在,我想這陣從AZ排序alphbetically並將它傳遞給表view.How我能做到這一點??? ... plz幫助

回答

0

使用NSSortDescriptor明白了....

這樣的事情,

NSSortDescriptor *alphaDesc = [[NSSortDescriptor alloc] initWithKey:@"boatName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]; 
    [[data boats] sortUsingDescriptors:[NSMutableArray arrayWithObjects:alphaDesc, nil]];