需求:
Cell中倒计时显示,到期刷新接口,超时数据消失。后端提供订单生成时间戳createdTime。
计算:
到期时间 = 订单生成时间+后端订单预留时间
剩余时间 = 到期时间 - 现在时间
剩余时间的年,月,日,时,分,秒都小于等于0时即为超时失效。
工具使用:CountDown
//导入文件,链接文章末尾
#import "CountDown.h"
@property (nonatomic , strong) CountDown *countDown;
//轮询初始化
self.countDown = [[CountDown alloc] init];
__weak __typeof(self) weakSelf= self;
[self.countDown countDownWithPER_SECBlock:^{
[weakSelf updateTimeInVisibleCells];
}];
//轮询并对Cell进行赋值
- (void)updateTimeInVisibleCells{
NSArray *cells = self.tableView.visibleCells; //取出屏幕可见ceLl
for (OpenCardWriteCell *cell in cells) {
OpenCardFailedModel *model = self.dataArray[cell.tag];
[cell.readBtn setTitle:[self getNowTimeWithString:validateString(model.createdTime)] forState:UIControlStateNormal];
}
}
//计算时间差
- (