可可应用程序(MAC)很慢

时间:2012-10-19 06:45:02

标签: macos cocoa nstimer nsviewcontroller nstabview

我正在使用基于计时器的应用程序,我在主运行循环中连续运行3个计时器,以便在任何UI更新的情况下计时器将持续运行。但过了一段时间(约1小时),我的应用程序挂起,而不是按钮等被按下的事件。它至少需要10-15秒才能响应。

我想知道MAC cocoa应用程序中的滞后原因是什么。我正在研究基于计时器的应用程序。所以我需要多个计时器才能运行。当没用时我也无效。但它仍然没有帮助我。

请指导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 :(得分:0)

您的问题是NSRunLoopCommonModes。使用scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:方法,它会在NSDefaultRunLoopMode中安排NSTimer。如果UI正在更新,您的应用程序将在以后获取其他事件。看一下this帖子。

相关问题