[ZOYSessionManager dataWithUrlString:GetVideoDataComment andParameter:@{@"id":userID,@"pageNo":@1,@"pageSize":@20}  SucessBlock:^(id data) {

//        NSDictionary * dic = [(NSData *)data  objectFromJSONData];

self->_mode=[CommunityModel mj_objectWithKeyValues:data];

NSLog(@"mode%@",self->_mode);

for (self->_itemmodel in self->_mode.content) {

[self.accountArray addObject:self->_itemmodel];

NSMutableArray *timeArr = [[NSMutableArray alloc]init];

NSMutableDictionary *dateKeyArr = [[NSMutableDictionary alloc]init];

for(CommunitItemModel *acc in _accountArray) {

// 时间戳转成时间对象用于排序

int timer = [acc.date intValue];

NSDate  *date = [NSDate dateWithTimeIntervalSince1970:timer];

[timeArr addObject:date];

// 时间戳转成时间戳字符串作为key,制作哈希表

NSNumber *dataNum = [NSNumber numberWithLongLong:timer];

NSString *datekey = [dataNum stringValue];

[dateKeyArr setObject:acc forKey:datekey];

}

// 3.将时间NSDate数组排序

NSArray *orderedDateArray = [timeArr sortedArrayUsingComparator:^NSComparisonResult(NSDate *date1, NSDate *date2) {

// 降序排序,最近的时间靠前

return [date2 compare:date1];

}];

// 4.根据排序好的时间数组对号入座将对象按时间排序

// 临时数组,保存排序后的对象数组

NSMutableArray *sortedAccounts = [[NSMutableArray alloc]init];

NSDate *datekey = [[NSDate alloc]init];

for (int i = 0; i<orderedDateArray.count; i++) {

datekey = orderedDateArray[i];

// 日期对象转换成时间戳字符串key

NSString *datekeys = [NSString stringWithFormat:@"%lld", (long long)[datekey timeIntervalSince1970]];

// 根据时间戳字符串key取对应的对象(哈希表)

[sortedAccounts addObject:[dateKeyArr objectForKey:datekeys]];

}

// 5.更新排序后的对象数组[ARC中不需要手动释放排序前的数组]

_accountArray = sortedAccounts;

self.dataArray = _accountArray;

//            [self.dataArray addObject:self->_itemmodel];

[self.myTableView reloadData];

}

//                NSLog(@"dataArray%@",self.dataArray);

[self.myTableView reloadData];

} failureBlock:^(NSError *error) {

NSLog(@"error  is  %@",error);

}];

NSLog(@"userID%@,@1,@20",userID);

self.myTableView.estimatedRowHeight = 80.0f;

self.myTableView.rowHeight = UITableViewAutomaticDimension;

//    [self.myTableView reloadData];

}

整合后的小demohttps://github.com/ZOYOOPlus/TimeSortDemo

iOS数组排序 请求后,数组元素的排序 时间戳,最热,点赞数等的更多相关文章

  1. 对数组元素进行排序的方法总结(利用C++)

    首先,对数组元素进行排序方法总结为以下两类: 一.简单排序算法(时间复杂度O(n*n)) 1.插入排序 2.选择排序 3.交换排序,即冒泡排序 二.先进排序算法(时间复杂度O(n*logn)) 1.快 ...

  2. c - 向一个排序好的数组插入一个数,插入后数组依然是排序好的

    概述 因为这里只是演示插入1个数,这里我不用malloc再重新分配,而是将原先数组的腾出一个占位符. 完整代码如下: #include <stdio.h> #define LEN 6 // ...

  3. C语言:通过指针对数组元素进行排序

    // //  main.c //  Pointer_array // //  Created by ma c on 15/8/2. //  Copyright (c) 2015年 bjsxt. All ...

  4. js将数组元素随机排序的方法

    在群里看见的一个面试题,试了一下,还是可以做出来的,但是需要查资料,主要是岁一些方法了解的不清楚,可能这个跟我平时不太注重基础理论有关系,像什么构造函数啊,我根本就不关心什么叫构造函数,我一直都以为我 ...

  5. php数组的各种排序

    转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/11/2207494.html 如果你已经使用了一段时间PHP的话,那么,你应 ...

  6. 数组Array.sort()排序的方法

    数组sort排序 sort比较次数,sort用法,sort常用 描述 方法sort()将在原数组上对数组元素进行排序,即排序时不创建新的数组副本.如果调用方法sort()时没有使用参数,将按字母顺序( ...

  7. shell脚本之数组基本操作及排序

    数组的基本操作及排序 1.数组定义方法: ( 6 7 9 4 3 2) 0 1 2 3 4 5 #下标号 方法一: 数组名=(value0 value1 value2 -) 方法二: 数组名=([0] ...

  8. [Swift]LeetCode462. 最少移动次数使数组元素相等 II | Minimum Moves to Equal Array Elements II

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  9. 462. 最少移动次数使数组元素相等 II

    给定一个非空整数数组,找到使所有数组元素相等所需的最小移动数,其中每次移动可将选定的一个元素加1或减1. 您可以假设数组的长度最多为10000. 例如: 输入: [1,2,3] 输出: 2 说明: 只 ...

随机推荐

  1. $.getJSON()函数内的数据不能传到全局变量是怎么回事?

    var json_obj2; $.getJSON("js/invite_panel.json",function(data){ json_obj2=data }) console. ...

  2. Swift学习笔记 - URL编码encode与解码decode

    使用swift有一段时间了,api的变换造成了很多困扰,下面是关于url编码和解码问题的解决方案 在Swift中URL编码 在Swift中URL编码用到的是String的方法 func addingP ...

  3. NuGet version

    https://stackoverflow.com/questions/15964935/get-nuget-exe-version-from-command-line Typing nuget he ...

  4. Memcached get 命令

    Memcached get 命令获取存储在 key(键) 中的 value(数据值) ,如果 key 不存在,则返回空. 语法: get 命令的基本语法格式如下: get key 多个 key 使用空 ...

  5. 关于Gulp

    Gulp & webpack 配置详解http://www.jianshu.com/p/2d9ed1fe3e8c 使用 Gulphttp://hwaphon.site/?p=439 前端构建工 ...

  6. [Vue]vee-validate的使用——自定义校验规则及校验message

    1.安装vee-validate npm install vee-validate --save 2.main.js里引用vee-validate插件 import Vue from 'vue' im ...

  7. Vue单页面中进行业务数据的上报

    为什么要在标题里加上一个业务数据的上报呢,因为在咱们前端项目中,可上报的数据维度太多,比如还有性能数据.页面错误数据.console捕获等.这里我们只讲解业务数据的埋点. 业务数据的上报主要分为: 各 ...

  8. 《Think in Java》(十三)字符串

    学完这章后,对 Java 字符串有了重新的认识.自己也看了下 CharSequence,String,StringBuilder,StringBuffer 等类的实现代码.

  9. 仅需15分钟,使用OpenCV+Keras轻松破解验证码

    https://baijia.baidu.com/s?id=1586732712477979223&wfr=pc&fr=app_lst

  10. centos 7网速监控脚本

    #!/bin/bashif [ $# -ne 1 ];thendev="eth0"elsedev=$1fi while :doRX1=`/sbin/ifconfig $dev |a ...