2016-06-08 6 views
0

UICollectionView에 셀에 카운트 다운 타이머를 구현하고 웹 서비스에서 시간을 얻었지만 다시 돌아올 때 정적 시간이 표시됩니다. UICollectionView 왼쪽 웹 서비스 시간에 따라 클래스 시간이 줄어 듭니다.UICollectionViewCell에서 라이브 타이머를 사용하는 방법은 무엇입니까?

그러나 나는 그것이 1 초로 감소 할 때마다 그것을 보여주고 싶습니다. 어떤 도움이라도 인정됩니다.

내 코드 :

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell 
{ 

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! ManageObjectCollectionViewCell 
    revealTime = getRevealtime[indexPath.section].objectAtIndex(indexPath.row) as! Int    
    minutes = revealTime/60   
    seconds = revealTime % 60 
    cell.HourLabel.text = "0" 
    cell.MinLabel.text = NSString(string: "\(minutes)") as String 
    cell.sec.text = NSString(string: "\(seconds)") as String 
} 
+0

정말 취소합니다. 예를 들어 설명해 주시겠습니까? – Shubhank

+0

업데이트가 필요할 때 (웹 서비스에서 새로운 시간을 가져 오거나 이미 가지고있는 정보를 기반으로 계산할 때) 'NSTimer' 객체 또는 다른 타이머를 트리거 할 수 있습니까? 새로운 시간을 가져 오면 지정된 색인에서 셀을 다시로드하거나 필요에 따라 모든 셀을 다시로드합니다. – DJohnson

답변

0
let currentTime = NSDate.timeIntervalSinceReferenceDate() 

    //Find the difference between current time and start time. 
    var elapsedTime: NSTimeInterval = currentTime - startTime 

    //calculate the hours in elapsed time. 
    let hours = UInt8(elapsedTime/3600.0) 
    elapsedTime -= (NSTimeInterval(hours) * 3600) 


    //calculate the minutes in elapsed time. 
    let minutes = UInt8(elapsedTime/60.0) 
    elapsedTime -= (NSTimeInterval(minutes) * 60) 

    //calculate the seconds in elapsed time. 
    let seconds = UInt8(elapsedTime) 
    elapsedTime -= NSTimeInterval(seconds) 

    //find out the fraction of milliseconds to be displayed. 
    // let fraction = UInt8(elapsedTime * 100) 

    //add the leading zero for minutes, seconds and millseconds and store them as string constants 

    let strMinutes = String(format: "%02d", minutes) 
    let strSeconds = String(format: "%02d", seconds) 
    let hourss = String(format: "%02d", hours) 

    //concatenate minuets, seconds and milliseconds as assign it to the UILabel 
    lblDisplayTime.text = "\(hourss):\(strMinutes):\(strSeconds)" 

사용이 코드

관련 문제