English 中文(简体)
1. 最新信息 二次观察数据
原标题:Update UITableView data every second

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

请注意,<代码>的现行是目前数据类型的一个实例。

最佳回答

最后,我发现,如果更新<代码>的现行<><><><><>>>代码>,则显示时间将自动更新。

问题回答

暂无回答




相关问题
Plist Hierarchy and All Option

I have a string of data in a plist, which I ve got to display, hierarchically like this: Menu>Chapter>SubChapter>item>item details This might be super simple, in my initial menu, how would I have ...

Disable iPhone table rows

Is there any way to disable the "selectibility" of a UITableView row? Example: I would like to make an appointment for a haircut at a certain time with a certain stylist. What gets displayed to a ...

Nonintrusive visual cue for uitableviewcell

I d like to mark a tableview row in some way that shows it has been clicked by the user. I have a large number of rows and want users to know if they have already visited a particular row. This same ...

TableView oval button for Index/counts

Can someone help me create an index/count button for a UITableView, like this one? iTunes http://img.skitch.com/20091107-nwyci84114dxg76wshqwgtauwn.preview.jpg Is there an Apple example, or other ...

Unable to pushViewController for subview

I have a UINavigationController and I have seperate UIViews that I switch between using a UISegmentControl. On switching the views, I add the view as a subview to my navigation controller s view: [...