【发布时间】:2012-10-19 06:45:01
【问题描述】:
我正在使用基于计时器的应用程序,我在主运行循环中连续运行 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];
【问题讨论】:
-
NSRunLoop *runloop = [NSRunLoop currentRunLoop]; updateServerTimeTimer = [NSTimer timerWithTimeInterval:1.0 目标:self 选择器:@selector(updateServerTime) userInfo:nil 重复:YES]; [runloop addTimer:updateServerTimeTimer forMode:NSRunLoopCommonModes];
-
我认为你的问题是 NSRunLoopCommonModes。为什么要使用 NSRunLoopCommonModes?
标签: macos cocoa nstimer nsviewcontroller nstabview