简体   繁体   中英

How to set different countdown timer to different labels of collectionviewcell in ios?

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.

  1. You can make the reference of the label you want to update in the collectionViewCell in the viewController, or
  2. You can make a separate model for CollectionViewCell and update the model from ViewController and call reload method of collectionView.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM