如何以时间比较的升序对nsmutablearray进行排序
这个问题在这里已经有了答案:
你可以使用下面的代码升序排列数组:
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
return [myArray sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
请使用以下代码: -
NSMutableArray *listOfTime = [[NSMutableArray alloc] initWithObjects:@"9:30",@"8:30",@"8:45",@"6:45",@"7:30", nil];
NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
NSArray *sorters = [[NSArray alloc] initWithObjects:sorter, nil];
NSArray *sortedArray = [listOfTime sortedArrayUsingDescriptors:sorters];
NSMutableArray *sortArray = [[NSMutableArray alloc] init];
[sortArray addObjectsFromArray:sortedArray];
NSLog(@"sortArray : %@",sortArray);
链接地址: http://www.djcxy.com/p/70813.html
上一篇: how to sort nsmutablearray in ascending order with time comparison