2014-02-08 130 views
0

我對UITableViewCell用定時器填充自定義UITableViewCell?

unsigned long long seconds = milliseconds/1000; 
unsigned long long minutes = seconds/60; 
unsigned long long hours = minutes/60; 

seconds -= minutes * 60; 
minutes -= hours * 60; 

NSString * result1 = [NSString `enter code here`stringWithFormat:@"%02lluH:%02lluM:%02lluS",hours,minutes,seconds]; 

self.menushowTime.text = result1;//populate cell label with time 

具有顯示時間的問題每當我重裝表中查看我的計時器與2倍的速度運行,我的意思是非常快的。我怎樣才能防止這種情況發生。

+0

如何是U計算毫秒? – santhu

+0

hm = components.hour * 3600000; NSUInteger mm = components.minute * 60000; NSUInteger sm = components.second * 1000; currentTime = hm + mm + sm; NSLog(@「show current time%lld」,currentTime); 這是我如何計算 – Abhishek

+0

和一切工作正常,面臨問題時,我開始滾動tableview或重新加載tableview – Abhishek

回答

2
facing problem when i start scrolling tableview or reloading the tableview.? 

是它發生,因爲計時器連接到NSRunLoop,所以當UI thread是忙着做動畫,NSRunLoop已經暫停。它完成動畫並稍後增加您的計時器。所以在這段時間內計時器不會完美增加。

使用下面的一個,

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; 
+0

該怎麼做才能顯示正確的tme – Abhishek

+0

檢查編輯的答案 – santhu

+0

我完全沒有得到如何觸發我的計時器馬新手,請你提供一些很好的例子,如何在uitableviewcell中顯示時間 – Abhishek

0

首先計算分鐘,稍後秒
將您的代碼更改爲以下。

minutes -= hours * 60; 
seconds -= minutes * 60;