iOS 在每一个cell上添加一个定时器的方案

1 首先创建一个数组,用来创建所有的定时器的时间

- (NSMutableArray *)totalLastTime
{
    if (!_totalLastTime) {
        _totalLastTime = [NSMutableArray array];
    }
    return _totalLastTime;
}

2 当从网络请求过来时间之后,循环遍历,行数和时间作为Key,将值作为value放进字典中放进数组

            // 所有剩余的时间  lastTime
            for (int i = 0; i < strongSelf.bigModel.activeTeamList.count; i ++) {
                NSDictionary *dic = strongSelf.bigModel.activeTeamList[i];
                
                NSDate *date = [SKTool changeTimeStringtoDate:dic[@"EndTime"]];
                
                double time =  [date timeIntervalSinceDate:[NSDate date]];
                
                NSMutableDictionary *para = [NSMutableDictionary dictionary];
                [para setValue:@(i) forKey:@"row"];
                [para setValue:[NSNumber numberWithDouble:time] forKey:@"lastTime"];
                [self.totalLastTime addObject:para];
            }
            

3 没定时器更新的方法中去取出row 和 时间,更新到cell 上面去,然后再将更新过的时间更新到数组中去。

- (void)refreshLessTime {
    
    NSUInteger time;
    
    for (int i = 0; i < self.totalLastTime.count; i++) {
        
        time = [[[self.totalLastTime objectAtIndex:i] objectForKey:@"lastTime"]integerValue];
        
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[[[self.totalLastTime objectAtIndex:i] objectForKey:@"row"] integerValue] inSection:1];
    
        BaoPinCellA *cell = (BaoPinCellA *)[self.tableView cellForRowAtIndexPath:indexPath];
        cell.timeLbL.text = [NSString stringWithFormat:@"剩余:%@",[self lessSecondToDay:--time]];
        NSDictionary *dic = @{@"row": [NSString stringWithFormat:@"%li",(long)indexPath.row],@"lastTime": [NSString stringWithFormat:@"%lu",(unsigned long)time]};
        [self.totalLastTime replaceObjectAtIndex:i withObject:dic];
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值