I have some table cells displaying different time. I want the time to be updated (just like countdown).
我试图每二次打电话<代码>[my_table_name reloadData],但该方法没有在上援引逻辑。 我如何通过UITableView的囚室更新其内容?
<>UPDATE:所示时间为10天 11:12:<49/code> (每间囚室有一个到期日,当表格更新时,到期日减去目前的时间和营地;计算其余时间,显示在囚室。)
<><>UPDATE 2 有两个方法重载数据。 一个是从服务器打电话的,一个是只使用服务器。
- (void)reloadLocal {
[my_table_name reloadData];
}
在线方法是:
- (void)reloadFromServer {
[self parseXML:@"URL here"];
}
- (void)parseXML:(NSString *)URL {
// read the XML & update a NSArray containing the data
}
www.un.org/Depts/DGACM/index_french.htm (viewDidLoad
)
current = [[NSDate date] retain];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(reloadLocal) userInfo:nil repeats:YES];
缩略语 方法,这里是假冒代码(长到所有线):
static NSString *identifier = @"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:identifier owner:nil options:nil];
for (id currendObj in topLevelObjects) {
if ([currendObj isKindOfClass:[UITableViewCell class]]) {
cell = (CustomCell *)currendObj;
break;
}
}
// then insert data to related UIOutlet elements.
NSDate *validUntil = [[NSDate alloc] initWithTimeInterval:diff sinceDate:current];
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:current toDate:validUntil options:0];
cell.lbl_day.text = [NSString stringWithFormat:@"%d", [conversionInfo day]];
cell.lbl_minute.text = [NSString stringWithFormat:@"%d", [conversionInfo minute]];
cell.lbl_second.text = [NSString stringWithFormat:@"%d", [conversionInfo second]];
cell.lbl_hour.text = [NSString stringWithFormat:@"%d", [conversionInfo hour]];
请注意,<代码>的现行代码>是目前数据类型