簡體   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