2012-10-19 26 views
-2

我正在使用基於計時器的應用程序,我在主運行循環中連續運行3個計時器,以便在任何UI更新的情況下計時器將持續運行。但經過一段時間後(大約1小時),我的應用程序將掛起,而不是按下按鈕等按鈕。響應時間至少需要10-15秒。可可App。 (MAC)非常慢

我想知道MAC可可應用中滯後的原因是什麼。我正在開發基於計時器的應用程序。所以我需要多個計時器來運行。無用時我也無效。但它仍然沒有幫助我。

請指導任何性能調試也爲mac,這樣我可以檢查我的代碼創建問題等?

代碼:

NSRunLoop *runloop = [NSRunLoop currentRunLoop]; 
updateServerTimeTimer = [NSTimer timerWithTimeInterval:1.0 
               target:self 
               selector:@selector(updateServerTime) 
               userInfo:nil 
               repeats:YES]; 
[runloop addTimer:updateServerTimeTimer forMode:NSRunLoopCommonModes]; 
+1

向我們展示您的代碼。 –

+0

NSRunLoop * runloop = [NSRunLoop currentRunLoop]; updateServerTimeTimer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(updateServerTime)userInfo:nil repeatats:YES]; [runloop addTimer:updateServerTimeTimer forMode:NSRunLoopCommonModes]; – york

+0

我認爲你的問題是NSRunLoopCommonModes。爲什麼你想使用NSRunLoopCommonModes? –

回答

0

你的問題是NSRunLoopCommonModes。使用scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:方法,它將在NSDefaultRunLoopMode安排的NSTimer。如果UI正在更新,您的應用程序將在稍後收到其他事件。看看this的帖子。