i want to put a label in table view cell that will display a countdown from a certain time. I have another view in that cell that slides left and right. Its starting position is most right but if the user wants it then can be dragged to left. The problem i face is that lets say the user dragged that view to left and then the timer triggered a method to countdown then the view moves back to right. Here how my code looks like
Here how timer method looks like
Why the view moves right back ? The cell is created when the timer is triggered ?
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @ContestsCell;
ContestsCell *theCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSDictionary *currentDictionary = self.contests[indexPath.row];
if (![[currentDictionary objectForKey:@lastDate] isEqualToString:@00:00:00]) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@en_US]];
[formatter setDateFormat:@HH:mm:ss];
self.countdownDate = [formatter dateFromString:[currentDictionary objectForKey:@lastDate]];
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(handleTimer:) userInfo:formatter repeats:YES];
[timer fire];
}
return theCell;
}
Here how timer method looks like
Code:
- (void)handleTimer:(NSTimer*)theTimer {
NSDateFormatter *formatter = (NSDateFormatter*)[theTimer userInfo];
self.countdownDate = [self.countdownDate dateByAddingTimeInterval:-1.0];
NSIndexPath *path = [NSIndexPath indexPathForItem:0 inSection:0];
ContestsCell *candiateCell = [self.contestsTable cellForRowAtIndexPath:path];
candiateCell.timeLabel.text = [formatter stringFromDate:self.countdownDate];
}
Why the view moves right back ? The cell is created when the timer is triggered ?