开发者

NSMutuableArray sort problem

NSMutableArray *labels; and it is properly populated.

    NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO];
labels = [labels sortedArrayUsingDescriptors: [NSArray arrayWithObje开发者_Python百科ct: sortOrder]];    

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance.

Even if I change NSArray to NSMutuableArray in the last line, I still get the error.

Thanks


dont assign the same array to it.if it is nsarray which is immutable.

so do like this

put ur

   labels as NSMutableArray


NSMutableArray *resultArray;

NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO];


resultArray = [[labels sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortOrder]] mutableCopy];    

self.labels=resultArray;//updated code

NSLog(@"resultArray : %@ \n\n",resultArray);


NSArray * descriptors = [NSArray arrayWithObjects: sortOrder, nil];
labels = [labels sortedArrayUsingDescriptors:descriptors];

This should do the trick for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜