每秒更新一次UITableView数据

每秒更新一次UITableView数据,uitableview,Uitableview,我有一些表格单元格显示不同的时间。我希望时间像倒计时一样被更新 我试图每秒调用[my_table_name reloadData],但该方法不调用cellForRowAtIndexPath中的逻辑。如何循环UITableView的单元格以更新其内容 更新:显示的时间以10天11:12:49的形式显示,每个单元格都有一个到期日期,更新表格时,到期日期减去当前时间并计算剩余时间,剩余时间显示在单元格上 更新2:有两种方法可以重新加载数据。一个是从服务器调用,一个是只调用函数 - (void)relo

我有一些表格单元格显示不同的时间。我希望时间像倒计时一样被更新

我试图每秒调用[my_table_name reloadData],但该方法不调用cellForRowAtIndexPath中的逻辑。如何循环UITableView的单元格以更新其内容

更新:显示的时间以10天11:12:49的形式显示,每个单元格都有一个到期日期,更新表格时,到期日期减去当前时间并计算剩余时间,剩余时间显示在单元格上

更新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
}
在viewDidLoad中调用reloadLocal方法如下

对于cellForRowAtIndexPath方法,以下是太长而无法发布所有行的伪代码:

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

请注意,current是当前时间的一个实例,数据类型为NSDate。

最后我发现,如果我在reloadLocal中更新日期变量current,显示的时间将自动更新。

请告诉我们如何每秒调用reloadData。但如何调用reloadLocal?您正在使用NSTimer吗?请给我们看一下密码。同时给我们看一下你的手机号码。你确定时间到了吗?在reloadLocal中放入一条NSLog语句以进行检查。根据NSLogYeah,事件正在触发。我刚刚也注意到了这一点。我建议您在调试时学习如何使用断点。无论如何,祝你的应用程序的其余部分好运。
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]];