【发布时间】:2015-07-13 14:59:48
【问题描述】:
我有如下的字典数组,我需要根据“create_time”作为 UITableView 的section-title 对下面的数组进行分段。并相应地加载到 tableview 中。请帮助如何使格式化数组具有节。
({
content = hellow;
"create_time" = 1436797644;
"from_id" = 290;
"from_name" = waterfall;
"group_id" = "<null>";
id = 1;
"send_time" = 1436797644;
"session_id" = 1436797620;
"state_id" = 0;
"to_id" = 289;
"to_name" = prof2;
"type_id" = 1;
} );
这是关于我所做的代码的一些小东西:
arr_CompleteChat=[[DataBaseController getInstance] readChat:userID withFromId:friendID withLimit:20];
SqlStatementt =[NSString stringWithFormat:@"SELECT * FROM MessageList where (from_id=%ld and to_id=%ld) OR (from_id=%ld and to_id=%ld) order by create_time DESC LIMIT %d",(long)[to_id integerValue],(long)[from_id integerValue],mode,(long)[from_id integerValue],(long)[to_id integerValue],limit];
关于表格视图的加载:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr_CompleteChat count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[[arr_CompleteChat objectAtIndex:indexPath.row]valueForKey:@"from_id"] isEqualToString:[[NSUserDefaults standardUserDefaults] valueForKey:@"MY_ID"]])
{
static NSString *CellIdentifier = @"CellIdentifier";
SendMsgBubbleCell *temp=(SendMsgBubbleCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (temp == nil)
{
temp = [[SendMsgBubbleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SendMsgBubbleCell" owner:temp options:nil];
[temp loaditemwithMessageArray:[arr_CompleteChat objectAtIndex:indexPath.row]];
temp=[topLevelObjects objectAtIndex:0];
}
return temp;
}
else
{
static NSString *CellIdentifier = @"CellIdentifier";
ReciveMsgBubbleCell *temp=(ReciveMsgBubbleCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (temp == nil)
{
temp = [[ReciveMsgBubbleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ReciveMsgBubbleCell" owner:temp options:nil];
[temp loaditemwithMessageArray:[arr_CompleteChat objectAtIndex:indexPath.row] ];
temp=[topLevelObjects objectAtIndex:0];
}
return temp;
}
}
现在我希望在 UItableview 的部分中转换整个 arr_completechat。我猜它的代码 sn-p 足以理解。
【问题讨论】:
-
您最好将您的相关代码提供给我们,看看您做了什么,以便我们更轻松地提供帮助。
标签: ios objective-c iphone uitableview