【问题标题】:Table View with Section for Date range带有日期范围部分的表格视图
【发布时间】:2012-08-14 09:41:34
【问题描述】:

我在表格视图中显示了以下数据

// declaration of Array
 NSMutableArray *listOfItems;

//Initialize the array.
listOfItems = [[NSMutableArray alloc] init];

// Adding Item to array
[listOfItems addObject:[object description]];

// Populating tableView with Array
NSString *cellValue = [listOfItems objectAtIndex:[indexPath row]]; 

显示:

  • 2012-08-10 07:52:39 +0000

    2012-08-10 07:56:46 +0000

    2012-08-10 07:57:01 +0000

    2012-08-13 02:14:02 +0000

    2012-08-13 02:20:29 +0000

    2012-08-10 07:56:46 +0000

    2012-08-14 08:44:33 +0000

现在我需要一个分段的表格视图,这样最终的结果应该是这样的

  • 标题

    • 2012-08-10

    价值观

    • 2012-08-10 07:52:39 +0000
    • 2012-08-10 07:56:46 +0000
    • 2012-08-10 07:57:01 +0000
    • 2012-08-10 07:56:46 +0000
  • 标题

    • 2012-08-13

    价值观

    • 2012-08-13 02:14:02 +0000
    • 2012-08-13 02:20:29 +0000

    • 标题 2012-08-14

    价值观

    • 2012-08-14 08:44:33 +0000

即每天的标题和每个部分中每天的不同值 我该怎么做?

【问题讨论】:

  • 只是一点帮助,没有代码:我建议您为您的项目列表创建 2 个数组。创建一个方法来处理将您的项目分离到这些数组中。它应该使用您的标题日期创建一个数组,并在另一个数组(二维)中添加带有值的数组。然后,您将按照正确的顺序填写您的日期以填写表格视图。我不知道你想如何显示你的标题数据和你的值之间的差异?也许您可以为每个包含您的值的单元格添加一些空格,以创建“折叠”效果。

标签: objective-c datetime nsmutablearray nsarray


【解决方案1】:
NSMutableArray *array=[[NSMutableArray alloc]init];
[array addObject:[NSArray alloc]initWithObjets:@"2012-08-10 07:52:39 +0000",@"2012-08-10    07:56:46 +0000",@"2012-08-10 07:57:01 +0000",nil]];
[array addObject:[NSArray alloc]initWithObjets:@"2012-08-13 02:14:02 +0000",@"2012-08-13 02:20:29 +0000",nil]];
[array addObject:[NSArray alloc]initWithObjets:@"2012-08-14 08:44:33 +0000",nil]];
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return array.count;
}
-(NSInteger)tableView:(UITableView *)tableViewl numberOfRowsInSection:(NSInteger)section
{
    NSArray *tempArray=[array objectAtIndex:section];
    return tempArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableViewl cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *tempArray=[array objectAtIndex:indexPath.session]
    cell.textLabel.text=[tempArray objectAtIndex:indexPath.row];
    return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSArray *tempArray=[array objectAtIndex:section];
    return [tempArray objectAtIndex:0];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-09
    • 2019-07-16
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多