简体   繁体   English

如何在iOS中为CollectionViewCell的不同标签设置不同的倒数计时器?

[英]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. 我正在一个应用程序上工作,我必须在事件中还剩几秒钟(所有事件都有所不同),然后我必须在每个collectionviewcell中打印事件的倒数时间(即剩余时间)。这里的行数是5假设吧。

- (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 您可以在viewController的collectionViewCell中引用要更新的标签,或者
  2. You can make a separate model for CollectionViewCell and update the model from ViewController and call reload method of collectionView. 您可以为CollectionViewCell创建一个单独的模型,并从ViewController更新模型,并调用collectionView的reload方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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