- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 NSArray,我想用数组对包含相同日期的所有对象进行分组。我想对这些对象进行分组,然后将它们显示在 TableView 中,并将具有相同日期的对象分组在 TableView 中各自的部分中。在每个部分中,我希望按事件发生的时间从最早到最晚列出事件。
检索到的数据来自 Parse 数据库。 (不确定这是否重要)。
下面是数组结果
DATA (
"<Sessions:QtJKSToEu9:(null)> {\n date = \"2013-11-19 18:30:00 +0000\";\n description = \"Seating assignment on name badge.\";\n location = \"Center Stage\";\n name = \"Dinner and CARE Awards Celebration\";\n}",
"<Sessions:btZ5eRZffl:(null)> {\n date = \"2013-11-19 20:30:00 +0000\";\n description = \"Brief meeting\";\n location = \"Cedar Room\";\n name = \"Store Manager Advisory Board Members\";\n}",
"<Sessions:HY4VtgBncd:(null)> {\n date = \"2013-11-20 07:00:00 +0000\";\n description = Breakfast;\n location = Ballrooms;\n name = Breakfast;\n}",
"<Sessions:6p6t2uL5Jf:(null)> {\n date = \"2013-11-20 11:30:00 +0000\";\n description = Lunch;\n location = Ballrooms;\n name = Lunch;\n}",
"<Sessions:TpEHi5Glsk:(null)> {\n date = \"2013-11-20 17:00:00 +0000\";\n description = \"Cocktails - Ballroom Pre-Function Area\";\n location = Ballroom;\n name = Cocktails;\n}",
"<Sessions:e9yEi6vFoE:(null)> {\n date = \"2013-11-20 18:00:00 +0000\";\n description = \"Welcome from Tony Kenney followed by dinner\";\n location = Ballrooms;\n name = Welcome;\n speaker = \"Tony Kenney\";\n}",
"<Sessions:kTG4NemPX4:(null)> {\n date = \"2013-11-20 19:30:00 +0000\";\n description = \"We Are Speedway Awards Night\";\n location = \"Center Stage\";\n name = \"Awards Night\";\n}",
"<Sessions:L9I8BIVECe:(null)> {\n date = \"2013-11-21 07:30:00 +0000\";\n description = Breakfast;\n location = \"Center Stage\";\n name = Breakfast;\n}",
"<Sessions:WUGRHDpHyo:(null)> {\n date = \"2013-11-21 12:00:00 +0000\";\n description = Lunch;\n location = \"Center Stage\";\n name = Lunch;\n}",
"<Sessions:r61f5NZr66:(null)> {\n date = \"2013-11-21 09:15:00 +0000\";\n description = \"Marketing Breakouts \\U2013 Rotation\\no\\tStart times for rotations: 9:15, 9:50, 10:25, 11:00, 11:35\\no\\tPlease see your name tag for your Group #2 room assignment.\\no\\tThe speaker will direct you to your next session.\\n\";\n location = Various;\n name = \"Marketing Breakouts \";\n}",
"<Sessions:RXkIDNIYoQ:(null)> {\n date = \"2013-11-20 13:30:00 +0000\";\n description = \"o\\tPlease see your name tag for your Group #1 room assignment\";\n location = Various;\n name = \"Division Breakouts\";\n}",
"<Sessions:lLI2PxdCdx:(null)> {\n date = \"2013-11-21 13:30:00 +0000\";\n description = \"Closing Comments by Tony Kenny\";\n location = \"Center Stage\";\n name = \"Closing Comments\";\n speaker = \"Tony Kenny\";\n}",
"<Sessions:KWz7Xen5a6:(null)> {\n date = \"2013-11-20 13:00:00 +0000\";\n description = \"Special Guest Speaker Gary Heminger\";\n location = \"Center Stage\";\n name = \"Special Guest Speaker\";\n speaker = \"Gary Heminger\";\n}",
"<Sessions:AU1x3LlUrF:(null)> {\n date = \"2013-11-21 08:30:00 +0000\";\n description = \"Marketing Focus by Tom LeFevers\";\n location = \"Center Stage\";\n name = \"Marketing Focus\";\n speaker = \"Tom LeFevers\";\n}",
"<Sessions:36TIRrD0s5:(null)> {\n date = \"2013-11-20 08:00:00 +0000\";\n description = \"Operations Focus by Glenn Plumby\";\n location = \"Center Stage\";\n name = \"Operations Focus\";\n speaker = \"Glenn Plumby\";\n}",
"<Sessions:tTvppNFM7L:(null)> {\n date = \"2013-11-19 17:00:00 +0000\";\n description = \"Cocktails \\U2013 Center Stage pre-function area. NOTE: Group photographs scheduled for select field personnel\\nin the lobby bar. (Appointment time on name badge.)\";\n location = \"Center Stage pre-function area \";\n name = Cocktails;\n}"
)
如何将包含相同日期(例如“2013-11-19”)的对象全部归为一个部分?
更新 使用 Artur Answers + 轻微修改以满足我的需要
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
int section = 0;
dataSource = [NSMutableArray new];
[dataSource addObject:[NSMutableArray array]];
for (int i = 0; i < _events.count - 1; i++) {
EventInfo *firstEvent = _events[i];
EventInfo *secondEvent = _events[i+1];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MMMM, dd"];
NSString *firstDateString = [df stringFromDate:firstEvent.details.date];
NSString *secondDateString = [df stringFromDate:secondEvent.details.date];
sectionArray = dataSource[section];
if (![sectionArray containsObject:firstEvent]) {
[sectionArray addObject:firstEvent];
}
if (![firstDateString compare:secondDateString] == NSOrderedSame) {
NSMutableArray *newSection = [NSMutableArray array];
[newSection addObject:secondEvent];
[dataSource addObject:newSection];
section++;
}
}
[dataSource.lastObject addObject:_events.lastObject];
最佳答案
NSMutableArray *dataSource = [NSMutableArray new];
// Sorting your array by date asc
array = [[array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
YourObject *firstObject = obj1;
YourObject *secondObject = obj2;
return [secondObject.date compare:firstObject.date] == NSOrderedAscending;
}] mutableCopy];
int section = 0;
[dataSource addObject:[NSMutableArray array]]; //Adding first section
for (int i = 0; i < array.count - 1; i++) {
YourObject *firstObject = array[i];
YourObject *secondObject = array[i+1];
NSDate *firstDate = [self dateWithoutTimePart:firstObject.date];
NSDate *secondDate = [self dateWithoutTimePart:secondObject.date];
NSMutableArray *sectionArray = dataSource[section];
if (![sectionArray containsObject:firstObject]) {
[sectionArray addObject:firstObject];
}
if (![firstDate compare:secondDate] == NSOrderedSame)
{
NSMutableArray *newSection = [NSMutableArray array];
[newSection addObject:secondObject];
[dataSource addObject:newSection];
section++;
}
}
// Adding last object to last section
[dataSource.lastObject addObject:array.lastObject];
这是一个快速编写的代码,对于可能出现的错误深表歉意:)
关于ios - 按 TableView 部分的日期对 NSArray 结果进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23202091/
您好,我正在处理 BIRT 报告。我有一个查询,我必须对父级的重复数据进行分组,但子级也不能分组! 在我的查询中: item 是父项,item_ledger_entry 是子项。我有来自 item.N
我正在使用 GA API。 这是针对 MCF 目标报告(底部)的标准目标完成指标表(顶部) 看一下这个: 总数加起来 (12,238),但看看按 channel 分组的分割有多么不同!我以为这些会很接
我正在开发一个流量计数器,我想获得 IP 和重复计数,但是如何? 就像是 :select ip, count(ip) from Redirect 返回 : null total ip count 重定
我尝试编写一个正则表达式来匹配条件表达式,例如: a!=2 1+2=2+a 我尝试提取运算符。我当前的正则表达式是“.+([!=<>]+).+” 但问题是匹配器总是尝试匹配组中可能的最短字符串
在 MS Transact SQL 中,假设我有一个这样的表(订单): Order Date Order Total Customer # 09/30/2008 8
我想按 m.ID 分组,并对每个 m.id 求和 (pm.amount_construction* prod.anzahl) 实际上我有以下结果: Meterial_id | amount_const
我想根据多列中的值对值进行分组。这是一个例子: 我想得到输出: {{-30,-50,20},{-20,30,60},{-30,NULL or other value, 20}} 我设法到达: SELE
我正在尝试找出运行此查询的最佳方式。我基本上需要返回在我们的系统中只下了一个订单的客户的“登录”字段列表(登录字段基本上是客户 ID/ key )。 我们系统的一些背景...... 客户在同一日期下的
给定以下mysql结果集: id code name importance '1234', 'ID-CS-B', 'Chocolate Sauce'
大家好,我的数据框中有以下列: LC_REF 1 DT 16 2C 2 DT 16 2C 3 DT 16 2C 1 DT 16 3C 6 DT 16 3C 3
我有这样的 mongoDB 集合 { "_id" : "EkKTRrpH4FY9AuRLj", "stage" : 10, }, { "_id" : "EkKTRrpH4FY9
假设我有一组数据对,其中 index 0 是值,index 1 是类型: input = [ ('11013331', 'KAT'), ('9085267',
java中用stream进行去重,排序,分组 一、distinct 1. 八大基本数据类型 List collect = ListUtil.of(1, 2, 3, 1, 2).stream().fil
基本上,我从 TABLE_A 中的这个开始 France - 100 France - 200 France - 300 Mexico - 50 Mexico - 50 Mexico - 56 Pol
我希望这个正则表达式 ([A-Z]+)$ 将选择此示例中的最后一次出现: AB.012.00.022ABC-1 AB.013.00.022AB-1 AB.014.00.022ABAB-1 但我没有匹配
我创建了一个数据透视表,但数据没有组合在一起。 任何人都可以帮助我获得所需的格式吗? 我为获取数据透视表而编写的查询: DECLARE @cols AS NVARCHAR(MAX), -- f
我想按时间段(月,周,日,小时,...)选择计数和分组。例如,我想选择行数并将它们按 24 小时分组。 我的表创建如下。日期是时间戳。 CREATE TABLE MSG ( MSG_ID dec
在 SQL Server 2005 中,我有一个包含如下数据的表: WTN------------Date 555-111-1212 2009-01-01 555-111-1212 2009-
题 假设我有 k 个标量列,如果它们沿着每列彼此在一定距离内,我想对它们进行分组。 假设简单 k 是 2 并且它们是我唯一的列。 pd.DataFrame(list(zip(sorted(choice
问题 在以下数据框中 df : import random import pandas as pd random.seed(999) sz = 50 qty = {'one': 1, 'two': 2
我是一名优秀的程序员,十分优秀!