从Unix时间戳日期ios数组在Uitableview中创建动态节? [英] Create dynamic Sections in Uitableview from array of Unix timestamp Date ios?
问题描述
我有一个表事件,其中日期"存储在Unix时间戳记formate(即1390680000)中,我想用Month Wise在uitableview中显示它,
I have table Events in which Dates are stored in Unix timestamp formate(i.e 1390680000) , I want to display it in uitableview with Month Wise,
我正在使用SQLITE3.
I am using SQLITE3.
喜欢
aray Events:(
{
Id = 67;
SDate = 1390680000;
},
{
Id = 68;
SDate = 1395600000;
}
.
.
.
我搜索了很多东西,但我找不到任何东西,
I have searched lot but i cant figure out any thing,
SO,如何从Unix时间戳日期ios在Uitableview中创建动态部分?
SO, How can i Create dynamic Section in Uitableview from Unix timestamp Date ios?
感谢所有人.
推荐答案
如果我输入错误,请纠正我,
Correct me if i wrong,
所有建议都在字典中使用字典数组,将两个对象放在标题(Nsstring)上,第二个对象放在NSArray(单元格详细信息字典)上,
As all suggests use Array of Dictionary in Dictionary put two object one for Title (Nsstring) and second is NSArray ( dict for cell detail),
我已经在我的应用中实现了一种方法,
I have implemented One method for that in my app,
注意:将您的键值用于数据.
使用以下代码排列数组,
Use Following code for Arranging Array,
-(NSMutableArray*)arrangeSection:(NSMutableArray *)source
{
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setLocale:[NSLocale currentLocale]];
[_formatter setDateFormat:@"MMMM"];
NSMutableArray *arrayMain=[NSMutableArray array];
for (int i=0; i<source.count; i++){
NSDictionary *dict=source[i];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[[dict objectForKey:@"StartDate"]doubleValue]];
NSString *mm=[_formatter stringFromDate:date];
NSMutableDictionary *secDict=[NSMutableDictionary dictionary];
NSMutableArray *secArray=[NSMutableArray array];
if (i==0){
[secDict setObject:mm forKey:@"Month"];
[secArray addObject:dict];
[secDict setObject:secArray forKey:@"Data"];
[arrayMain addObject:secDict];
}
else{
BOOL flg=NO;
for (NSDictionary *dict2 in arrayMain){
if([[dict2 objectForKey:@"Month"]isEqualToString:mm]){
flg=YES;
[[dict2 objectForKey:@"Data"]addObject:dict];
break;
}
}
if (!flg){
[secDict setObject:mm forKey:@"Month"];
[secArray addObject:dict];
[secDict setObject:secArray forKey:@"Data"];
[arrayMain addObject:secDict];
}
}
}
return arrayMain;
}
现在在Tableview中,方法用作,
Now in tableview Methods use as,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return arrayEvents.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[arrayEvents[section]objectForKey:@"Data"]count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
NSDictionary *aDict = [arrayEvents objectAtIndex:indexPath.section];
NSDictionary *maindict=[[aDict objectForKey:@"Data"]objectAtIndex:indexPath.row];
...
}
这篇关于从Unix时间戳日期ios数组在Uitableview中创建动态节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!