ios 排序相关排序代码如下:
//冒泡排序
-(void)bubblesort {
for (int i = 0; i < self.label.count-1; i++) {
UILabel *labi = self.label[i];
for (int j = i; j <self.label.count; j++) {
UILabel *labj = self.label [j];
if ([labi.text intValue] > [labj.text intValue]) {
NSLog(@"");
}
}
}
}
//可变数组冒泡排序
for (int i = 0; i < listArray.count; i++) {
VideoList *videoi = (VideoList *)listArray[i];
for (int j = i; j < listArray.count ; j++) {
VideoList *videoj = (VideoList *)listArray[j];
if ([videoi.sort intValue] < [videoj.sort intValue])
{
[listArray exchangeObjectAtIndex:i withObjectAtIndex:j];
}
}
}
//系统自带排序
- (void)parseArray
{
self.surArray = [self.array sortedArrayUsingComparator:^(id number1,id number2) {
int val1 = [[number1 objectForKey:@"type"] intValue];
int val2 = [[number2 objectForKey:@"type"] intValue];
if (val1 > val2)
{
return NSOrderedDescending;
}
else
{
return NSOrderedAscending;
}
}];
}