uitableview内的多个倒计时定时器

我如何去做这个任务? 基本上,我将在UITableView中列出一个“秒诠释”数组。 那么我怎样才能把每个“秒诠释”倒计时到零? 我看到的可能的问题是计时器没有被更新时,单元格尚未创build。 我怎么实例化多个独立的NSTimers更新不同的UI元素? 我很迷茫,所以有什么build议,非常感谢。 为了视觉目的,我想要这样的东西:

在这里输入图像说明

从图像看,你的模型看起来就是用户计划采取的一系列动作。 我会这样安排事情:

1)MyAction是一个名字和截止date的NSObject。 MyAction实现这样的东西:

- (NSString *)timeRemainingString { NSDate *now = [NSDate date]; NSTimeInterval secondsLeft = [self.dueDate timeIntervalSinceDate:now]; // divide by 60, 3600, etc to make a pretty string with colons // just to get things going, for now, do something simple NSString *answer = [NSString stringWithFormat:@"seconds left = %f", secondsLeft]; return answer; } 

2)StatusViewController保持对MyActions的NSArray模型的句柄,它也有一个NSTimer(只有一个)告诉它时间正在传递。

 // schedule timer on viewDidAppear // invalidate on viewWillDisappear - (void)timerFired:(NSTimer *)timer { [self.tableView reloadData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.model.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyAction *myAction = [self.model objectAtIndex:indexPath.row]; // this can be a custom cell. to get it working at first, // maybe start with the default properties of a UITableViewCell static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.textLabel.text = [myAction timeRemainingString]; cell.detailTextLabel.text = [myAction name]; } 

为了在表格中看上去很花哨的UI东西,你可能想要UITableViewCell的子类并在每个属性中创build一个定时器。 该单元可以拥有一个委托,响应TimerWentOff,并处理警报或通知或什么都不响。 每个计时器将更新它的单元格中的标签。

希望有点帮助。 如果您有更具体的问题,请告诉我。