- (void)timeChange {
self.totalSeconds --;
if (self.totalSeconds < 0) {
self.timerLabel.text = @"倒计时结束";
return;
}
self.timerLabel.text = [self timeChangeWithSeconds:self.totalSeconds];
}
- (void)setDataDict:(NSDictionary *)dataDict {
_dataDict = dataDict;
NSString *totalTime = dataDict[@"totalTime"];
self.totalSeconds = totalTime.integerValue;
self.timerLabel.text = [self timeChangeWithSeconds:self.totalSeconds];
if (!_timer) {
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:UITrackingRunLoopMode];
}
}
- (NSString*)timeChangeWithSeconds:(NSInteger)seconds {
NSInteger temp1 = seconds/60;
NSInteger temp2 = temp1/ 60;
NSInteger d = temp2 / 24;
NSInteger h = temp2 % 24;
NSInteger m = temp1 % 60;
NSInteger s = seconds %60;
NSString * hour = h< 9 ? [NSString stringWithFormat:@"0%ld",(long)h] :[NSString stringWithFormat:@"%ld",(long)h];
NSString *day = d < 9 ? [NSString stringWithFormat:@"0%ld",(long)d] : [NSString stringWithFormat:@"%ld",(long)d];
NSString *minite = m < 9 ? [NSString stringWithFormat:@"0%ld",(long)m] : [NSString stringWithFormat:@"%ld",(long)m];
NSString *second = s < 9 ? [NSString stringWithFormat:@"0%ld",(long)s] : [NSString stringWithFormat:@"%ld",(long)s];
return [NSString stringWithFormat:@"%@天:%@时:%@分:%@秒",day,hour,minite,second];
}
- (void)setDataDict:(NSDictionary *)dataDict {
_dataDict = dataDict;
if (self.totalSeconds !=0) {
self.timerLabel.text = [self timeChangeWithSeconds:self.totalSeconds];
}else {
NSString *totalTime = dataDict[@"totalTime"];
self.totalSeconds = totalTime.integerValue;
self.timerLabel.text = [self timeChangeWithSeconds:self.totalSeconds];
}
if (!_timer) {
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:UITrackingRunLoopMode];
}
}
/**定时器触发*/
- (void)timeChange {
NSMutableArray *tempArrM = [NSMutableArray array];
for (NSDictionary *dict in self.dataArr) {
NSString *totalTime = dict[@"totalTime"];
if ([totalTime isEqualToString:@"0"]) {
totalTime = @"0";
}else {
totalTime = [NSString stringWithFormat:@"%ld",totalTime.integerValue -1];
}
[tempArrM addObject:@{@"totalTime":totalTime}];
}
self.dataArr = tempArrM;
[self.pageTableView reloadData];
}
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeChange) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:_timer forMode:UITrackingRunLoopMode];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有