2010-09-21 57 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]];