2012-08-14 45 views
1

我從表視圖與節日期範圍

// 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 7時52分39秒+0000

    2012-08-10 7時56分46秒+0000

    2012-08-10 7時57分01秒+0000

    2012年8月13日2時14分02秒+0000

    2012年8月13日2時20分29秒+0000

    2012-08-10 7點56分46秒+0000

    2012-08-14 8時44分33秒+0000

現在我需要有一個分段表視圖,這樣最終的結果應該是這樣的

  • 部首

    • 2012-08-10

    • 2012-08-10 7點52分39秒0000
    • 2012-08-10 7點56分:46 +0000
    • 2012-08-10 07:57:01 +0000
    • 2012-08-10 07:56:46 +0000
  • 部首

    • 2012年8月13日

    • 2012年8月13日2點14分02秒0000
    • 2012-08 -13 02:20:29 +0000

    • 部首2012-08-14

    • 2012-08-14 8時44分33秒0000

即頭的每一天和不同每個部分每天的價值 我該怎麼做?

+0

就像一個幫助,沒有代碼: 我建議你只爲你的項目列表創建2個數組。創建一個處理將這些項分離到這些數組中的方法。它應該創建一個包含您的標題日期的數組,並在另一個數組(2D)中爲數組添加值。 然後,您將按照正確的順序填寫日期以填充表格。我不知道你想如何顯示你的標題數據和你的值之間的差異?也許你可以爲每個單元格添加一些空格,這些空格將包含你的值以創建「崩潰」效果。 – NDY 2012-08-14 11:11:05

回答

0
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]; 
}