根据后台返回的日期排序数据

    xiaoxiao2022-06-28  30

    1、数据数组套字典 ( { “add_date” = “2016.09.14 13:42”; “is_see” = 1; “message_content” = “\U6e29\U99a8\U63d0\U793a:\U3010123\U3011\U7684\U8ba2\U53551609071551228739\U5df2\U7ecf\U4ed8\U6b3e\Uff0c\U4ed8\U6b3e\U91d1\U989d606.56\U5143\Uff0c\U8bf7\U53ca\U65f6\U67e5\U770b!”; “message_header” = “2016\U5e7409\U6708”; “message_id” = TShort33349f2f77a24e70a919c2ce900890a6; “message_title” = “\U4ed8\U6b3e\U63d0\U9192”; “message_type” = “\U4ed8\U6b3e\U63d0\U9192”; }, { “add_date” = “2016.09.14 11:54”; “is_see” = 1; “message_content” = “\U6e29\U99a8\U63d0\U793a:\U60a8\U5728\U3010123\U3011\U7684\U8ba2\U53551608311659438511\U5df2\U7ecf\U53d6\U6d88\U8ba2\U5355\Uff0c\U8bf7\U53ca\U65f6\U67e5\U770b!”; “message_header” = “2016\U5e7409\U6708”; “message_id” = TShort28d7175e741f4692a84f598e57311f3c; “message_title” = “\U53d6\U6d88\U8ba2\U5355\U63d0\U9192”; “message_type” = “\U53d6\U6d88\U8ba2\U5355\U63d0\U9192”; }, { “add_date” = “2016.09.14 11:53”; “is_see” = 1; “message_content” = “\U6e29\U99a8\U63d0\U793a:\U60a8\U5728\U3010123\U3011\U7684\U8ba2\U53551608311659478980\U5df2\U7ecf\U53d6\U6d88\U8ba2\U5355\Uff0c\U8bf7\U53ca\U65f6\U67e5\U770b!”; “message_header” = “2016\U5e7409\U6708”; “message_id” = TShorta637b6c7faec48f0b8400271d2df7f02; “message_title” = “\U53d6\U6d88\U8ba2\U5355\U63d0\U9192”; “message_type” = “\U53d6\U6d88\U8ba2\U5355\U63d0\U9192”; }, )

    2、message_header是本次我们要拿来排序的日期 3、创建一个model放数据的字段 4、拿日期进行比较,相同的拼接放在同一个数组不同的放另一个数组,

    _messageNarray = [NSMutableArray arrayWithCapacity:0]; _currentMessageArray = [NSMutableArray arrayWithCapacity:0]; 效果图

    还可以这样 /*if (dic) { NSArray *dataArray = [dic objectForKey:@”backinfo”]; [dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { NSString *dateKey = [obj objectForKey:@”message_header”]; NSMutableArray *dateArray = [NSMutableArray arrayWithArray:[mutableDict objectForKey:dateKey]]; [dateArray addObject:obj]; [mutableDict setObject:dateArray forKey:dateKey]; }];

    //日期 NSMutableArray *dayArray = [NSMutableArray array]; //所有的天数 NSMutableArray *allDateArray = [NSMutableArray array]; //每一条 NSMutableArray *dateMutableArray = [NSMutableArray array]; for (NSString *dateKey in [mutableDict allKeys]) { NSMutableArray *dateKeyArray = mutableDict[dateKey]; for (id value in dateKeyArray) { MessageCenterModel *messageModel = [MessageCenterModel initWithDictionary:value]; [self.statusArr addObject:messageModel.is_see]; [dateMutableArray addObject:messageModel]; } [allDateArray addObject:dateMutableArray]; [dayArray addObject:dateKey]; }
    转载请注明原文地址: https://ju.6miu.com/read-1124493.html

    最新回复(0)