I am working on an application where I have to get seconds left in event (Which is different for all the events) and then I have to print the countdown time (ie time left) for event in each collectionviewcell.Number of rows here are 5 for suppose.
- (col *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
static NSString *identifier = @"Cell";col *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
secondsLeft= seconds left depending on data which I can get successfully;
[self start];
cell.lbl_time.text=[NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
return cell;} -(void)updateCounter:(NSTimer *)theTimer{
if(secondsLeft > 0 ) {
secondsLeft -- ;
hours = secondsLeft / 3600;
minutes = (secondsLeft % 3600) / 60;
seconds = (secondsLeft %3600) % 60;
//count.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
}
else
{
NSLog(@"Timer Invalidate");
// [timer invalidate];
}} -(void)start{
timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];}
Let me know what I should do. Thanks in advance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.