gpt4 book ai didi

iphone - uitableview 中的多个倒数计时器

转载 作者:可可西里 更新时间:2023-11-01 04:27:51 25 4
gpt4 key购买 nike

我该如何完成这项任务?基本上,我将在 UITableView 中列出一个“seconds int”数组。那么如何将每个“seconds int”分配给倒计时为零呢?我看到的可能问题是当单元格尚未创建时计时器未更新。以及如何实例化多个独立的 NSTimer 来更新不同的 ui 元素?我在这里很迷路,所以非常感谢任何建议。出于视觉目的,我想要这样的东西:

enter image description here

最佳答案

从图像上看,您的模型似乎是一组用户计划执行的操作。我会这样安排:

1) MyAction 是一个具有名称和截止日期的 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];
}

关于iphone - uitableview 中的多个倒数计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9918472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com