繁体   English   中英

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

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

我正在一个应用程序上工作,我必须在事件中还剩几秒钟(所有事件都有所不同),然后我必须在每个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];}

让我知道我该怎么办。 提前致谢。

  1. 您可以在viewController的collectionViewCell中引用要更新的标签,或者
  2. 您可以为CollectionViewCell创建一个单独的模型,并从ViewController更新模型,并调用collectionView的reload方法。

暂无
暂无

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

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