简体   繁体   English

iOS中按日期划分的UITableView

[英]Datewise Sectioned UITableView in iOS

I have NSMutableArray which has passenger's journey that will be shown in tableview. 我有NSMutableArray ,其中有乘客的旅程,将在表视图中显示。 I shows correctly in plain tableview. 我在普通表格视图中正确显示。 But I want to show in sectioned tableview where tableview headers will show date and its rows will will show all journey on that particular date. 但是我想在分段的tableview中显示,其中tableview标头将显示日期,并且其行将显示该特定日期的所有旅程。

I am not able to figure out how to first break my NSMuatableArray into various array(datewise) and then show it in sectioned tableView. 我无法弄清楚如何首先将我的NSMuatableArray分解成各种数组(按日期排列),然后在分段的tableView中显示它。

I am newbie to iPhone . 我是iPhone的新手。 Please help. 请帮忙。

I suppose that you have a array of Dictionary with some key to identify date. 我想您有一个包含一些关键字的Dictionary数组,用于标识日期。

Here I posted code for devide a Mutable Array to Datewise array. 在这里,我张贴了将Mutable Array改为Datewise数组的代码。

NSString *lastDate = @"";
NSMutableArray *aryInnerArray = nil;
NSmutableArray *aryChatConversation = [[NSMutableArray alloc] init];
for (NSDictionary *dict in aryTempChat) {
    if (![lastDate isEqualToString:[dict objectForKey:@"date"]]) {
        if (aryInnerArray != nil) {
            [aryChatConversation addObject:[NSDictionary dictionaryWithObjectsAndKeys:lastDate, @"date", aryInnerArray, @"conversation", nil]];
            [aryInnerArray release];
        }
        lastDate = [dict objectForKey:@"date"];
        aryInnerArray = [[NSMutableArray alloc] init];
    }
    [aryInnerArray addObject:dict];
}
if (aryInnerArray != nil) {
    [aryChatConversation addObject:[NSDictionary dictionaryWithObjectsAndKeys:lastDate, @"date", aryInnerArray, @"conversation", nil]];
    [aryInnerArray release];
}
[aryTempChat release];

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM