我的項目中有一個按鈕和一個標籤。單擊按鈕後,我需要啓動一個NSTimer
,它顯示標籤上的值。例如1sec.I我不確定計時器是否返回value.is有沒有其他的方式來做到這一點?在標籤上顯示NSTimer值
0
A
回答
0
點擊
{
NSTimer *t;
t=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showTimer) userInfo:nil repeats:YES];
}
在showTimer功能
-(void)showTimer{
static int i=0;
static int min=0;
if(i>=59){
i=0;
min++;
} else {
i++;
}
yourLabel.text=[NSString stringWithFormat:@" %d:%d ",min,i];
}
+0
你的方法錯了......請在有人降低你的評價之前糾正。 –
+0
哦..它應該是59 ..現在我糾正它/ –
+0
以及如何:'-showTimer {' –
0
NSTimer *aTimer = [NSTimer timerWithTimeInterval:(1) target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:aTimer forMode: NSDefaultRunLoopMode];
int i=0;
- (void)timerFired:(NSTimer*)theTimer
{
if(condition)
{
// timer repeat
// your actions
i++;
int conseconds = i % 60;
int conminutes = (i/60) % 60;
timelable.text=[NSString stringWithFormat:@"%02d:%02d", conminutes,conseconds];
[theTimer isValid];
}
else
{
// your actions
//timer stopped
[theTimer invalidate];
}
}
相關問題
- 1. NSTimer在標籤
- 2. Highcharts顯示在標籤上
- 3. NSTimer更新標籤
- 4. 標籤不顯示值
- 5. 顯示標籤上一行
- 6. 更新一個標籤,顯示10000使用的NSTimer
- 7. 如何在QwtSlider中顯示值標籤?
- 8. 在JavaFx標籤中顯示更改值
- 9. 如何在列表框中顯示XML值或如何在標籤上顯示。
- 10. 在標籤上顯示可選雙號
- 11. 在標籤上顯示刻度符號
- 12. Ico將不會顯示在標籤上
- 13. 在右上角顯示p標籤
- 14. Dojo Horizontal Slider在標籤上顯示
- 15. 在標籤上顯示數據
- 16. 如何在標籤上顯示陣列
- 17. 標籤不顯示在Jframe上
- 18. Chart.js在餅圖上顯示標籤
- 19. 如何在餅圖上顯示標籤
- 20. 從form2在form1上顯示標籤VB
- 21. 如何在x軸上顯示標籤?
- 22. DateTime.AddSeconds不會在標籤上顯示
- 23. 在Google地圖上顯示標籤
- 24. Flot - 在堆積條上顯示標籤
- 25. 標籤欄不顯示在TabbedPage上
- 26. 定時器在標籤上顯示HH:MM:SS
- 27. 顯示標籤jsp標籤
- 28. 我可以同時在MSChart的餅圖標籤上顯示標籤和值
- 29. 如何在xcode中使用標籤顯示標籤的值?
- 30. NSTimer倒計時標籤
你可以參考這個[教程](http://iphoneapp-dev.blogspot.in/2010 /10/how-to-create-countdown-timer-in-iphone.html)它會幫助你 – thavasidurai
感謝您的教程 – karthi
你有沒有得到解決方案 – thavasidurai